#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
#define sz(x) ((int)size(x))
#define trace(x) cout << #x << ": " << (x) << endl;
typedef long long ll;
const int N = 1000, M = 100000;
int A[M], B[M], C[2][M];
bool e[N][N];
vector<pair<int, int>> adj[N];
vector<pair<int, int>> g[2][M];
vector<pair<int, int>> st;
bool used[2][M];
bool usd[N];
void dfs(int t, int v, pair<int, int> p) {
used[t][v] = true;
usd[C[t][v]] = true;
st.emplace_back(t, v);
for (auto to: g[t][v]) {
if (to != p) {
if (used[to.first][to.second]) {
memset(usd, 0, sizeof(usd));
st.emplace_back(to);
int lst = -1;
while (!usd[C[st.back().first][st.back().second]]) {
auto mm = st.back();
cout << C[mm.first][mm.second] + 1 << " ";
if (lst != -1) {
assert(e[lst][C[mm.first][mm.second]]);
}
lst = C[mm.first][mm.second];
usd[C[mm.first][mm.second]] = true;
st.pop_back();
}
exit(0);
}
}
}
for (auto to: g[t][v]) {
if (to != p) {
if (!used[to.first][to.second]) {
dfs(to.first, to.second, {t, v});
}
}
}
usd[C[t][v]] = false;
st.pop_back();
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, r;
cin >> n >> r;
for (int i = 0; i < r; ++i) {
cin >> A[i] >> B[i];
--A[i], --B[i];
C[0][i] = A[i];
C[1][i] = B[i];
adj[A[i]].emplace_back(B[i], i);
adj[B[i]].emplace_back(A[i], i);
e[A[i]][B[i]] = e[B[i]][A[i]] = true;
}
for (int v = 0; v < n; ++v) {
for (auto [a, i]: adj[v]) {
for (auto [b, j]: adj[v]) {
if (i != j && !e[a][b]) {
int t1 = (B[i] == a);
int t2 = (B[j] == v);
g[t1][i].emplace_back(t2, j);
}
}
}
}
for (int v = 0; v < r; ++v) {
if (!used[0][v]) {
dfs(0, v, {-1, -1});
}
if (!used[1][v]) {
dfs(1, v, {-1, -1});
}
}
cout << "no";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Runtime error |
7 ms |
10068 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5076 KB |
Output is correct |
2 |
Runtime error |
7 ms |
10068 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
11092 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
9 ms |
11832 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
15 ms |
16772 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
112 ms |
72904 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
225 ms |
192724 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
146 ms |
19260 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |