#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<bool>> c(n, vector<bool>(n));
vector<vector<int>> g(n);
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
--x; --y;
c[x][y] = true;
c[y][x] = true;
g[x].push_back(y);
g[y].push_back(x);
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (c[i][j]) {
continue;
}
for (int k = 0; k < n; k++) {
if (i == k || j == k || !c[i][k] || !c[j][k]) {
continue;
}
vector<bool> del(n);
del[k] = true;
for (int p : g[k]) {
if (p != i && p != j) {
del[p] = true;
}
}
vector<int> p(n, -1);
function<void(int, int)> Dfs = [&](int v, int pv) {
p[v] = pv;
for (int u : g[v]) {
if (u == pv || p[u] != -1 || del[u]) {
continue;
}
Dfs(u, v);
}
};
Dfs(i, -1);
if (p[j] == -1) {
continue;
}
vector<int> seq;
for (int v = j; v != -1; v = p[v]) {
seq.push_back(v);
}
seq.push_back(k);
for (int i = 0; i < (int) seq.size(); i++) {
cout << seq[i] + 1 << " ";
}
cout << '\n';
return 0;
}
}
}
cout << "no" << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
452 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
973 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
945 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
348 KB |
Output is correct |
2 |
Runtime error |
952 ms |
1048576 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
945 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1062 ms |
264368 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1044 ms |
1048576 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
2140 KB |
Output is correct |
2 |
Correct |
11 ms |
2188 KB |
Output is correct |
3 |
Incorrect |
305 ms |
1948 KB |
Wrong adjacency |
4 |
Halted |
0 ms |
0 KB |
- |