fork download
  1. #include<bits/stdc++.h>
  2. #define endl "\n"
  3. using namespace std;
  4. typedef long long ll;
  5. const int MAXN = 1001;
  6. const int MOD = 1e9+7;
  7.  
  8. int n, m, a[MAXN];
  9.  
  10. void input(){
  11. memset(a, 0, sizeof(a));
  12. cin >> n >> m;
  13. for(int i=0; i<m; i++){
  14. int x, y;
  15. cin >> x >> y;
  16. a[x]++;
  17. a[y]++;
  18. }
  19. }
  20.  
  21. void check(){
  22. int count = 0;
  23. for(int i=1; i<=n; i++){
  24. if((a[i] % 2) != 0){
  25. count++;
  26. }
  27. }
  28. if(count == 0) {
  29. cout << 2 << endl;
  30. }
  31. else if(count == 2){
  32. cout << 1 << endl;
  33. }
  34. else {
  35. cout << 0 << endl;
  36. }
  37. }
  38.  
  39. int main(){
  40. int t;
  41. cin >> t;
  42. while(t--){
  43. input();
  44. check();
  45. }
  46. return 0;
  47. }
Success #stdin #stdout 0s 5320KB
stdin
2

6  10  

1 2 2 4 2 5 3 1 3 2 4 3 4 5 5 3 5 6 6 4

3 3

1 2 2 3 1 3
stdout
2
2