fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define maxn 100001
  4. vector<int>adj[maxn];
  5. vector<int>visited(maxn,0);
  6. //int count = 1;
  7. int ck = 1, cr =1;
  8. int p=0;
  9. void bfs(int s, int* count){
  10. queue<int> Q;
  11. Q.push(s);
  12. while(!Q.empty()){
  13. int temp = Q.front();
  14. Q.pop();
  15. for(int i =0; i<adj[temp].size(); i++){
  16. if(visited[adj[temp][i]] == 0 && abs(adj[temp][i] - temp) == 1){
  17. visited[adj[temp][i]] = 1;
  18. Q.push(adj[temp][i]);
  19. *count++;
  20. if(p ==0)
  21. cr++;
  22. else
  23. ck++;
  24. }
  25. }
  26. }
  27. }
  28. string Maximum(int r, int k, int n){
  29. int count = 1;
  30.  
  31. while(count != n){
  32. if(p ==0)
  33. {
  34. bfs(r, &count);
  35. p =1;
  36. }
  37. else
  38. {
  39. bfs(k, &count);
  40. p =0;
  41. }
  42. }
  43. if(cr>ck)
  44. return "Rama";
  45. else
  46. return "Krishna";
  47. }
  48.  
  49.  
  50. int main(){
  51. int n = 4;
  52. //for(int i =0; i<maxn; i++)
  53. //visited[i] = 0;
  54. int a, b;
  55. for(int i=0; i<6; i++){
  56. cin>>a>>b;
  57. adj[a].push_back(b);
  58. }
  59. cout<<Maximum(1,n, n)<<endl;
  60. }
  61.  
Time limit exceeded #stdin #stdout 5s 5948KB
stdin
1 2 
2 3 
2 4
stdout
Standard output is empty