#include <bits/stdc++.h>
#define N 1005
using namespace std;
int vis[N][N];
bool adj[N][N];
int par[N][N];
int n;
void dfs(int a,int b){
vis[a][b] = 1;
//cout << a << " " << b << endl;
for(int i=1;i<=n;i++){
if(i != a && adj[b][i] && !adj[a][i]){
if(vis[b][i] == 1){
vector<int> nodes;
int st = b;
nodes.push_back(b);
nodes.push_back(a);
while(par[a][b] != st && par[a][b]){
nodes.push_back(par[a][b]);
int tmp = b;
b = a;
a = par[a][tmp];
}
for(auto u:nodes){
cout << u << " ";
}
exit(0);
}
else if(!vis[b][i]){
par[b][i] = a;
dfs(b,i);
}
}
}
vis[a][b] = 2;
}
void solve(){
int m;
cin >> n >> m;
vector<pair<int,int>> edges;
for(int i=1;i<=m;i++){
int a,b;
cin >> a >> b;
adj[a][b] = adj[b][a] = 1;
edges.push_back({a,b});
edges.push_back({b,a});
}
for(auto u:edges){
if(!vis[u.first][u.second]){
dfs(u.first,u.second);
}
}
cout << "no";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
while(t--){
solve();
}
#ifdef Local
cout << endl << fixed << setprecision(2) << 1000.0 * clock() / CLOCKS_PER_SEC << " milliseconds.";
#endif
}
/*
14 15
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 1
4 11
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
596 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
2 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3044 KB |
Output is correct |
2 |
Correct |
3 ms |
2140 KB |
Output is correct |
3 |
Correct |
2 ms |
1044 KB |
Output is correct |
4 |
Correct |
14 ms |
3156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2132 KB |
Output is correct |
2 |
Correct |
7 ms |
2796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
9624 KB |
Output is correct |
2 |
Correct |
21 ms |
7564 KB |
Output is correct |
3 |
Correct |
253 ms |
10404 KB |
Output is correct |
4 |
Correct |
87 ms |
9768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
5780 KB |
Output is correct |
2 |
Correct |
115 ms |
8844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
5028 KB |
Output is correct |
2 |
Correct |
139 ms |
4852 KB |
Output is correct |
3 |
Correct |
16 ms |
3052 KB |
Output is correct |
4 |
Correct |
387 ms |
10604 KB |
Output is correct |