Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include <cmath>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <iostream>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8. int number=0;
  9. int numberOf(vector<vector<int>> mygraph,int current,int n, vector<bool> visited)
  10. {
  11.  
  12. vector<int> :: iterator itr;
  13. visited[current]=true;
  14. int count =1;
  15. for(itr=mygraph[current].begin();itr!=mygraph[current].end();itr++)
  16. {
  17. if(!visited[*itr])
  18. {
  19. count += numberOf(mygraph,*itr,n,visited);
  20. }
  21. }
  22. if(count%2==0)
  23. {
  24. number++;
  25. }
  26. return count;
  27. }
  28. int main() {
  29. /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  30. int n;
  31. int m;
  32. cin>>n>>m;
  33. vector<vector<int>> mygraph(n);
  34. vector<bool> visited(n,false);
  35. for(int i=0;i<m;i++)
  36. {
  37. int from;
  38. int to;
  39. cin>>from>>to;
  40. mygraph[from-1].push_back(to-1);
  41. mygraph[to-1].push_back(from-1);
  42.  
  43. }
  44. numberOf(mygraph,0,n,visited);
  45. cout<<number-1;
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement