Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

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

$
0
0

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 ;

}


Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>