Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<vector>
- #include<stack>
- using namespace std;
- int const N = 100010;
- int color[N];
- vector<int> adj[N];
- bool check(int u){
- if(color[u] == 2)return false;
- if(color[u] == 1)return true;
- color[u] = 1;
- bool ans = false;
- for(int i=0;i<adj[u].size() && !ans;i++){
- ans = check(adj[u][i]);
- }
- if(!ans) color[u] = 2;
- return ans;
- }
- int main()
- {
- int n,m;
- scanf("%d %d",&n,&m);
- for(int i=0;i<m;i++){
- int u,v;
- scanf("%d %d",&u,&v);
- adj[u].push_back(v);
- }
- bool ans = false;
- for(int i=1;i<=n && !ans;i++){
- ans = check(i);
- }
- printf("%s",(ans ? "Yes" : "No"));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement