Advertisement
Slayerfeed

E-sport

Mar 30th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5. int visited[100010];
  6. bool error;
  7. vector<int>  esport[100010];
  8. bool compet(int x)
  9. {
  10.     if(visited[x]==1)
  11.     {
  12.         return true;
  13.     }
  14.     if(visited[x]==2)
  15.     {
  16.         return false;
  17.     }
  18.     visited[x]=1;
  19.     for(auto c : esport[x])
  20.     {
  21.         if(compet(c))
  22.         {
  23.             return true;
  24.         }
  25.     }
  26.     visited[x]=2;
  27.     return false;
  28.  
  29. }
  30.  
  31. int main()
  32. {
  33.     int n,m;
  34.     cin >> n >> m;
  35.     int u,v;
  36.     for(int i=0; i<m; ++i)
  37.     {
  38.         cin >> u >> v;
  39.         esport[u].push_back(v);
  40.     }
  41.  
  42.  
  43.     for(int i=1; i<=n; ++i)
  44.     {
  45.         if(visited[i]!=2)
  46.         {
  47.             if(compet(i))
  48.             {
  49.                 error=true;
  50.  
  51.             }
  52.         }
  53.     }
  54.  
  55.     if(error)
  56.     {
  57.         cout << "Yes";
  58.     }
  59.     else
  60.     {
  61.         cout << "No";
  62.     }
  63.  
  64.     return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement