#include <iostream>
#include <cstring>
#define MAXV 100
typedef struct {
int numVertices;
int numEdges;
char VerticesList[MAXV];
int Edge[MAXV][MAXV];
} MGraph;
int findVertexIndex(MGraph* graph, char vertex) {
for (int i = 0; i < graph->numVertices; i++) {
if (graph->VerticesList[i] == vertex) {
return i;
}
}
return -1;
}
MGraph* createGraph(int vertices) {
MGraph* graph = new MGraph();
graph->numVertices = vertices;
graph->numEdges = 0;
for (int i = 0; i < vertices; i++) {
graph->VerticesList[i] = 'A' + i;
for (int j = 0; j < vertices; j++) {
graph->Edge[i][j] = 0;
}
}
return graph;
}
void addEdge(MGraph* graph, char src, char dest) {
int srcIndex = findVertexIndex(graph, src);
int destIndex = findVertexIndex(graph, dest);
if (srcIndex == -1 || destIndex == -1) {
std::cout << "Invalid vertex\n";
return;
}
if (!graph->Edge[srcIndex][destIndex]) {
graph->Edge[srcIndex][destIndex] = 1;
graph->Edge[destIndex][srcIndex] = 1;
graph->numEdges++;
}
}
void printGraph(MGraph* graph) {
std::cout << "Adjacency Matrix:\n";
std::cout << " ";
for (int i = 0; i < graph->numVertices; i++) {
std::cout << graph->VerticesList[i] << " ";
}
std::cout << "\n";
for (int i = 0; i < graph->numVertices; i++) {
std::cout << graph->VerticesList[i] << " ";
for (int j = 0; j < graph->numVertices; j++) {
std::cout << graph->Edge[i][j] << " ";
}
std::cout << "\n";
}
}
int IsExistEL(MGraph G){
int v=0;
for(int i=0;i<G.numVertices;i++){
int count=0;
for(int j=0;j<G.numVertices;j++){
if(G.Edge[i][j]==1){
count++;
}
}
if(count%2!=0){
v++;
}
}
if(v==0 || v==2){
return 1;
}
else
return 0;
}
int printVertices(MGraph G){
int ans=0;
int a[G.numVertices]={0};
int b[G.numVertices]={0};
for(int i=0;i<G.numVertices;i++){
int count1=0;
int count2=0;
for(int j=0;j<G.numVertices;j++){
if(G.Edge[i][j]==1){
count1++;
G.Edge[j][i]=0;
}
}
for(int j=0;j<G.numVertices;j++){
if(G.Edge[j][i]==1){
count2++;
}
}
if(count1>count2){
printf("%c",G.VerticesList[i]);
ans++;
}
}
return ans;
}
int main() {
MGraph* graph = createGraph(4);
addEdge(graph, 'A', 'B');
addEdge(graph, 'B', 'C');
addEdge(graph, 'B', 'D');
addEdge(graph, 'A', 'D');
addEdge(graph, 'C', 'D');
printf("%d",printVertices(*graph));
delete graph;
return 0;
}