Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.136 s | 47 KBi |
#2 |
Correcto
|
0.183 s | 50 KBi |
#3 |
Correcto
|
0.181 s | 49 KBi |
#4 |
Correcto
|
0.132 s | 54 KBi |
#5 |
Correcto
|
0.145 s | 48 KBi |
#6 |
Correcto
|
0.132 s | 48 KBi |
#7 |
Correcto
|
0.143 s | 47 KBi |
#8 |
Correcto
|
0.132 s | 47 KBi |
#9 |
Correcto
|
0.131 s | 47 KBi |
#10 |
Correcto
|
0.127 s | 48 KBi |
#11 |
Correcto
|
0.128 s | 49 KBi |
#12 |
Correcto
|
0.13 s | 48 KBi |
#13 |
Correcto
|
0.128 s | 48 KBi |
#14 |
Correcto
|
0.157 s | 47 KBi |
#15 |
Correcto
|
0.131 s | 48 KBi |
#16 |
Correcto
|
0.146 s | 48 KBi |
#17 |
Correcto
|
0.143 s | 47 KBi |
#18 |
Correcto
|
0.126 s | 48 KBi |
#19 |
Correcto
|
0.13 s | 47 KBi |
#20 |
Correcto
|
0.133 s | 48 KBi |
#21 |
Correcto
|
0.132 s | 47 KBi |
#22 |
Correcto
|
0.14 s | 48 KBi |
#23 |
Correcto
|
0.14 s | 47 KBi |
#24 |
Correcto
|
0.193 s | 52 KBi |
#25 |
Correcto
|
0.185 s | 51 KBi |
#26 |
Correcto
|
0.149 s | 48 KBi |
#27 |
Correcto
|
0.17 s | 49 KBi |
#28 |
Correcto
|
0.148 s | 47 KBi |
#29 |
Correcto
|
0.183 s | 48 KBi |
#30 |
Correcto
|
0.148 s | 48 KBi |
#31 |
Correcto
|
0.149 s | 48 KBi |
#32 |
Correcto
|
0.195 s | 48 KBi |
#33 |
Correcto
|
0.18 s | 49 KBi |
#34 |
Correcto
|
0.15 s | 49 KBi |
#35 |
Correcto
|
0.191 s | 50 KBi |
//kosaraju algorithm #include <bits/stdc++.h> using namespace std; #define endl '\n' #define ll long long #define pii pair<int, int> const int maxi = 1e6; vector<vector<int>>g1(maxi); vector<vector<int>>g2(maxi); vector<bool>vis(maxi); stack<int>s; void dfs(int u){ vis[u] = true; for(auto i: g1[u]){ if(!vis[i]){ dfs(i); } } s.push(u); } void dfs2(int u){ vis[u] = true; for(auto i: g2[u]){ if(!vis[i]){ dfs2(i); } } } int main(){ ios::sync_with_stdio(0); cin.tie(0); int n, m; cin>>n>>m; bool flag = false; for(int i=0;i<m;i++){ int a, b; cin>>a>>b; g1[a].push_back(b); g2[b].push_back(a); if(a==b){ flag = true; } } if(flag){ cout<<"Yes"<<endl; return 0; } for(int i=0; i<n;i++){ if(!vis[i]){ dfs(i); } } vis.assign(n, false); int comp = 0; while(s.size()){ int i = s.top(); s.pop(); if(!vis[i]){ dfs2(i); comp++; } } // cout<<comp<<endl; if(comp == n){ cout<<"No"<<endl; }else{ cout<<"Yes"<<endl; } return 0; }