#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ii pair<int, int>
#define f first
#define s second
#define vii vector<ii>
vii adj[1000];
bool conn[1000][1000];
vii edges;
vi adj2[100000];
bool vis[100000];
vector<int> S;
void dfs(int u, int p) {
if (vis[u]) {
vector<int> ans;
while (true) {
int x = S.back(); S.pop_back();
if (!ans.empty() && ans.back() == edges[x].f) {
ans.push_back(edges[x].s);
} else {
ans.push_back(edges[x].f);
}
if (u == x) break;
}
for (int x : ans) cout << x+1 << " ";
cout << endl;
exit(0);
}
vis[u] = true;
S.push_back(u);
for (auto v : adj2[u]) {
if (v != p) dfs(v, u);
}
S.pop_back();
}
int main() {
int n, r; cin >> n >> r;
for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) conn[i][j] = false;
for (int i = 0; i < r; i++) {
vis[i] = false;
int a, b; cin >> a >> b; --a; --b;
conn[a][b] = true;
conn[b][a] = true;
edges.push_back({a,b});
adj[a].push_back({b,i});
adj[b].push_back({a,i});
}
for (int i = 0; i < r; i++) {
int a = edges[i].f, b = edges[i].s;
for (auto v : adj[a]) {
if (v.f == b || conn[b][v.f]) continue;
adj2[v.s].push_back(i);
}
for (auto v : adj[b]) {
if (v.f == a || conn[a][v.f]) continue;
adj2[v.s].push_back(i);
}
}
for (int i = 0; i < r; i++) {
if (!vis[i]) dfs(i, i);
}
cout << "no" << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2816 KB |
Output is correct |
3 |
Correct |
6 ms |
2688 KB |
Output is correct |
4 |
Correct |
6 ms |
2688 KB |
Output is correct |
5 |
Correct |
6 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
2688 KB |
Repeated vertex |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Too short sequence |
2 |
Incorrect |
6 ms |
2688 KB |
Wrong answer on graph without induced cycle |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
2816 KB |
Repeated vertex |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
3072 KB |
Repeated vertex |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
3328 KB |
Wrong answer on graph without induced cycle |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
4608 KB |
Repeated vertex |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
139 ms |
20940 KB |
Repeated vertex |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
126 ms |
49476 KB |
Repeated vertex |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
154 ms |
6888 KB |
Repeated vertex |
2 |
Halted |
0 ms |
0 KB |
- |