#include <bits/stdc++.h>
using namespace std;
const int mxN = 1005, mxM = 2e5 + 5;
int n, m, u[mxM], v[mxM], adj1[mxN][mxN]; vector<int> adj2[mxM], stk; bool vis[mxM], active[mxM];
void dfs(int cur, int p){
vis[cur] = active[cur] = 1; stk.push_back(cur);
for (int nxt : adj2[cur]) if (nxt != p and active[nxt]){
while (stk.back() != nxt){
cout<<u[stk.back()]<<" ";
stk.pop_back();
}
cout<<u[stk.back()]<<endl;
exit(0);
}
for (int nxt : adj2[cur]) if (nxt != p and !vis[nxt]) dfs(nxt, cur);
active[cur] = 0; stk.pop_back();
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; i++){
int a, b; cin >> a >> b;
u[i * 2] = a; v[i * 2] = b;
u[i * 2 + 1] = b; v[i * 2 + 1] = a;
adj1[a][b] = i * 2; adj1[b][a] = i * 2 + 1;
}
for (int i = 1; i <= 2 * m; i++)
for (int j = 1; j <= n; j++)
if (adj1[v[i]][j] and j != u[i])
if (!adj1[u[i]][j])
adj2[i].push_back(adj1[v[i]][j]);
for (int i = 1; i <= 2 * m; i++) if (!vis[i]) dfs(i, 0);
cout<<"no"<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
5024 KB |
Output is correct |
3 |
Correct |
4 ms |
5012 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
2 ms |
4940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5028 KB |
Output is correct |
2 |
Correct |
3 ms |
5068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5668 KB |
Output is correct |
2 |
Correct |
4 ms |
5708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
6476 KB |
Output is correct |
2 |
Correct |
8 ms |
6476 KB |
Output is correct |
3 |
Correct |
17 ms |
8432 KB |
Output is correct |
4 |
Correct |
22 ms |
8396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
7668 KB |
Output is correct |
2 |
Correct |
11 ms |
7756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
314 ms |
24872 KB |
Output is correct |
2 |
Correct |
76 ms |
12412 KB |
Output is correct |
3 |
Correct |
278 ms |
25148 KB |
Output is correct |
4 |
Correct |
80 ms |
12360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
143 ms |
53804 KB |
Output is correct |
2 |
Correct |
159 ms |
57884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
153 ms |
8900 KB |
Output is correct |
2 |
Correct |
153 ms |
9284 KB |
Output is correct |
3 |
Correct |
472 ms |
93000 KB |
Output is correct |
4 |
Correct |
498 ms |
92992 KB |
Output is correct |