This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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, i);
if (p[j] == -1) {
continue;
}
vector<int> seq;
for (int v = j; ; v = p[v]) {
seq.push_back(v);
if (v == i) {
break;
}
}
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |