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