Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int visited[100010];
- bool error;
- vector<int> esport[100010];
- bool compet(int x)
- {
- if(visited[x]==1)
- {
- return true;
- }
- if(visited[x]==2)
- {
- return false;
- }
- visited[x]=1;
- for(auto c : esport[x])
- {
- if(compet(c))
- {
- return true;
- }
- }
- visited[x]=2;
- return false;
- }
- int main()
- {
- int n,m;
- cin >> n >> m;
- int u,v;
- for(int i=0; i<m; ++i)
- {
- cin >> u >> v;
- esport[u].push_back(v);
- }
- for(int i=1; i<=n; ++i)
- {
- if(visited[i]!=2)
- {
- if(compet(i))
- {
- error=true;
- }
- }
- }
- if(error)
- {
- cout << "Yes";
- }
- else
- {
- cout << "No";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement