Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define MOD 1e9 + 7
  4. #define endl '\n'
  5.  
  6. int main()
  7. {
  8. ios_base::sync_with_stdio(0); cin.tie(0);
  9.  
  10. int n,m;
  11.  
  12. cin >> n >> m;
  13.  
  14. vector<vector<int> > adj(n);
  15.  
  16. for(int i = 0;i < m;i++)
  17. {
  18. int a,b;
  19. cin >> a >> b;
  20. adj[a].push_back(b);
  21. adj[b].push_back(a);
  22. }
  23.  
  24. queue<pair<pair<int,int>,int> > q;
  25.  
  26. for(int i = 0;i < n;i++)
  27. {
  28. while(!q.empty()) q.pop();
  29. q.push({{i,i},1});
  30. while(!q.empty())
  31. {
  32. int st = q.front().first.first,p = q.front().first.second,sz = q.front().second;
  33. q.pop();
  34. if(p==st and sz>1 and sz%2==0){ cout << "Gay found!"; return 0; }
  35. if(p==st and sz>1) continue;
  36. for(int i = 0;i < adj[p].size();i++) q.push({{st,adj[p][i]},sz+1});
  37. }
  38. }
  39.  
  40. cout << "Gay not found!";
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement