Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.014 s | 3 KBi |
#2 |
Correcto
|
0.015 s | 4 KBi |
#3 |
Correcto
|
0.016 s | 4 KBi |
#4 |
Correcto
|
0.014 s | 4 KBi |
#5 |
Correcto
|
0.014 s | 4 KBi |
#6 |
Correcto
|
0.01 s | 4 KBi |
#7 |
Correcto
|
0.015 s | 3 KBi |
#8 |
Correcto
|
0.014 s | 4 KBi |
#9 |
Correcto
|
0.011 s | 4 KBi |
#10 |
Correcto
|
0.012 s | 4 KBi |
#11 |
Correcto
|
0.012 s | 4 KBi |
#12 |
Correcto
|
0.014 s | 3 KBi |
#13 |
Correcto
|
0.011 s | 4 KBi |
#14 |
Correcto
|
0.011 s | 4 KBi |
#15 |
Correcto
|
0.012 s | 4 KBi |
#16 |
Correcto
|
0.014 s | 4 KBi |
#17 |
Correcto
|
0.014 s | 4 KBi |
#18 |
Correcto
|
0.015 s | 4 KBi |
#19 |
Correcto
|
0.013 s | 4 KBi |
#20 |
Correcto
|
0.014 s | 4 KBi |
#21 |
Correcto
|
0.014 s | 4 KBi |
#22 |
Correcto
|
0.016 s | 4 KBi |
#23 |
Correcto
|
0.013 s | 4 KBi |
#24 |
Correcto
|
0.014 s | 3 KBi |
#25 |
Correcto
|
0.011 s | 4 KBi |
#26 |
Correcto
|
0.013 s | 4 KBi |
#27 |
Correcto
|
0.059 s | 5 KBi |
#28 |
Correcto
|
0.014 s | 4 KBi |
#29 |
Correcto
|
0.069 s | 4 KBi |
#30 |
Correcto
|
0.021 s | 4 KBi |
#31 |
Correcto
|
0.026 s | 4 KBi |
#32 |
Correcto
|
0.015 s | 4 KBi |
#33 |
Correcto
|
0.03 s | 6 KBi |
#34 |
Correcto
|
0.036 s | 5 KBi |
#35 |
Correcto
|
0.088 s | 6 KBi |
#include <iostream> #include <map> #include <vector> #include <stack> using namespace std; #define ll long long const int N = 50000+10; vector<vector<int>>g1(N); vector<vector<int>>g2(N); stack<int>s; vector<bool> vis(N); void dfs1(int u){ vis[u] =1; for(int i: g1[u]){ if(!vis[i]){ dfs1(i); } } s.push(u); } void dfs2(int u){ vis[u] =1; for(int i: g2[u]){ if(!vis[i]){ dfs2(i); } } } int main(){ ios::sync_with_stdio(0); cin.tie(0); int n, m; cin>>n>>m; 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){ cout<<"Yes"<<endl; return 0; } } for(int i=0;i<n;i++){ if(!vis[i]){ dfs1(i); } } vis.assign(n, false); int comp =0; while(s.size()){ if(!vis[s.top()]){ dfs2(s.top()); comp++; } s.pop(); } if(comp == n){ cout<<"No"<<endl; }else{ cout<<"Yes"<<endl; } return 0; }