#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;
int first = -1;
bool second = true;
while (true) {
int x = S.back(); S.pop_back();
if (first == -1) {
first = x;
continue;
}
if (second) {
second = false;
if (edges[x].f == edges[first].f || edges[x].f == edges[first].s) {
ans.push_back(edges[x].f);
ans.push_back(edges[x].s);
} else if (edges[x].s == edges[first].f || edges[x].s == edges[first].s) {
ans.push_back(edges[x].s);
ans.push_back(edges[x].s);
} else {
assert(false);
}
} else {
if (!ans.empty() && ans.back() == edges[x].f) {
ans.push_back(edges[x].s);
} else {
//assert(ans.back() == edges[x].s);
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 |
Incorrect |
6 ms |
2688 KB |
Repeated vertex |
2 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
7 ms |
2944 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 |
156 ms |
20684 KB |
Repeated vertex |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
132 ms |
49384 KB |
Repeated vertex |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
150 ms |
6248 KB |
Repeated vertex |
2 |
Halted |
0 ms |
0 KB |
- |