Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.016 s | 4 KBi |
#2 |
Incorrecto
|
0.011 s | 4 KBi |
#3 |
Incorrecto
|
0.014 s | 4 KBi |
#4 |
Correcto
|
0.014 s | 4 KBi |
#5 |
Incorrecto
|
0.015 s | 4 KBi |
#6 |
Correcto
|
0.021 s | 4 KBi |
#7 |
Correcto
|
0.013 s | 4 KBi |
#8 |
Correcto
|
0.011 s | 4 KBi |
#9 |
Correcto
|
0.014 s | 4 KBi |
#10 |
Correcto
|
0.012 s | 4 KBi |
#11 |
Correcto
|
0.012 s | 4 KBi |
#12 |
Incorrecto
|
0.013 s | 4 KBi |
#13 |
Correcto
|
0.014 s | 4 KBi |
#14 |
Incorrecto
|
0.014 s | 4 KBi |
#15 |
Correcto
|
0.013 s | 4 KBi |
#16 |
Correcto
|
0.014 s | 3 KBi |
#17 |
Correcto
|
0.015 s | 3 KBi |
#18 |
Incorrecto
|
0.015 s | 4 KBi |
#19 |
Correcto
|
0.014 s | 3 KBi |
#20 |
Incorrecto
|
0.014 s | 4 KBi |
#21 |
Incorrecto
|
0.015 s | 3 KBi |
#22 |
Incorrecto
|
0.013 s | 4 KBi |
#23 |
Correcto
|
0.011 s | 4 KBi |
#24 |
Incorrecto
|
0.017 s | 5 KBi |
#25 |
Incorrecto
|
0.014 s | 4 KBi |
#26 |
Incorrecto
|
0.012 s | 4 KBi |
#27 |
Incorrecto
|
0.075 s | 5 KBi |
#28 |
Incorrecto
|
0.016 s | 4 KBi |
#29 |
Incorrecto
|
0.07 s | 5 KBi |
#30 |
Incorrecto
|
0.015 s | 4 KBi |
#31 |
Incorrecto
|
0.026 s | 4 KBi |
#32 |
Correcto
|
0.016 s | 4 KBi |
#33 |
Correcto
|
0.037 s | 5 KBi |
#34 |
Correcto
|
0.033 s | 5 KBi |
#35 |
Correcto
|
0.083 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<m;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; }