#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, m;
int nxt[N][N];
bool E[N][N];
bool finish[N][N];
vector<int> res;
void check() {
int sz = res.size();
for (int i = 0; i < sz; ++i) {
for (int j = i + 2; j < sz; ++j) {
if (i == 0 && j == sz - 1) continue;
assert(!E[res[i]][res[j]]);
}
}
for (int i = 0; i < sz; ++i) {
assert(E[res[i]][res[(i + 1) % sz]]);
}
for (auto i : res) cout << i << ' ';
}
void dfs(int x, int y) {
for (int i = 1; i <= n; ++i) {
if (E[y][i] && !E[x][i] && i != x && !finish[y][i]) {
if (nxt[y][i]) {
int curx = x, cury = y;
while (curx != y && cury != i) {
res.push_back(cury);
int tmp = nxt[curx][cury];
cury = curx, curx = tmp;
}
res.push_back(cury), check();
exit(0);
}
else nxt[y][i] = nxt[i][y] = x, dfs(y, i);
}
}
finish[x][y] = finish[y][x] = 1;
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= m; ++i) {
int u, v; cin >> u >> v;
E[u][v] = E[v][u] = 1;
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
if (!E[i][j] || nxt[i][j]) continue;
nxt[i][j] = nxt[j][i] = i, dfs(i, j);
}
}
cout << "no";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
8092 KB |
Output is correct |
2 |
Correct |
0 ms |
8092 KB |
Output is correct |
3 |
Correct |
0 ms |
8092 KB |
Output is correct |
4 |
Correct |
0 ms |
8092 KB |
Output is correct |
5 |
Correct |
0 ms |
8092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
8092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
8092 KB |
Output is correct |
2 |
Correct |
0 ms |
8092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
0 ms |
8096 KB |
Execution killed because of forbidden syscall gettid (186) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
8092 KB |
Output is correct |
2 |
Correct |
0 ms |
8092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8092 KB |
Output is correct |
2 |
Runtime error |
0 ms |
8096 KB |
Execution killed because of forbidden syscall gettid (186) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8092 KB |
Output is correct |
2 |
Correct |
3 ms |
8092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
83 ms |
8096 KB |
Execution killed because of forbidden syscall gettid (186) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
8092 KB |
Output is correct |
2 |
Correct |
46 ms |
8092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
8092 KB |
Output is correct |
2 |
Correct |
123 ms |
8092 KB |
Output is correct |
3 |
Correct |
116 ms |
8092 KB |
Output is correct |
4 |
Correct |
249 ms |
8092 KB |
Output is correct |