Advertisement
SuitNdtie

Esport used colorPP

Mar 28th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<vector>
  3. #include<stack>
  4. using namespace std;
  5. int const N = 100010;
  6. int color[N];
  7. vector<int> adj[N];
  8.  
  9. bool check(int u){
  10.     if(color[u] == 2)return false;
  11.     if(color[u] == 1)return true;
  12.     color[u] = 1;
  13.     bool ans = false;
  14.     for(int i=0;i<adj[u].size() && !ans;i++){
  15.         ans = check(adj[u][i]);
  16.     }
  17.     if(!ans) color[u] = 2;
  18.     return ans;
  19. }
  20.  
  21. int main()
  22. {
  23.     int n,m;
  24.     scanf("%d %d",&n,&m);
  25.     for(int i=0;i<m;i++){
  26.         int u,v;
  27.         scanf("%d %d",&u,&v);
  28.         adj[u].push_back(v);
  29.     }
  30.     bool ans = false;
  31.     for(int i=1;i<=n && !ans;i++){
  32.         ans = check(i);
  33.     }
  34.     printf("%s",(ans ? "Yes" : "No"));
  35.    
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement