What's wrong with my code (Sereja and Graph) (SEAGRP) ?

The code basically counts the number of nodes with even order and number of nodes with odd order and if they both are even individually, then it prints yes and no otherwise .

#include <iostream>
 
using namespace std;
 
int main(){

int x,y,even,odd,flag;
int test;
cin >> test;
int a[100];
int n,m;	
for(int i = 0 ; i < test; i++){
even = odd = 0;
flag = 0;
cin >> n >> m;
for(int k = 0 ;k<=n;k++){
     a[k] = 0;
}
for(int j = 0 ; j < m ; j++){
    cin >> x >> y;
    a[x]++;
    a[y]++;	
}
for(int j = 1 ; j <= n ; j++){
    if(a[j] == 0){
         flag++;	
    }else if(a[j]%2 != 0){
         odd++;	
    }else{
     even++;	
    }	
}
if(flag == 0 && even%2 == 0 && odd%2 == 0){
          cout << "YES" << endl;
}else{
      cout << "NO" << endl;
}	
 }
 return 0 ;

}

@achut1993 : your logic is wrong . You need to find a maximum matching in the graph and if the size of matching * 2 = number of vertices then the answer is “YES” otherwise “NO” .

maximum matching problem is solved by reducing it to max flow problem

To learn more

//