#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];
bool e[N][N];
vector<pair<int, int>> adj[N];
vector<int> g[M];
vector<int> st, sus;
bool used[M];
void dfs(int v, int p) {
used[v] = true;
st.push_back(v);
for (int to: g[v]) {
if (to != p) {
if (!used[to]) {
dfs(to, v);
} else {
sus.push_back(to);
while (st.back() != to) {
sus.push_back(st.back());
st.pop_back();
}
for (int i = 0; i < sz(sus) - 1; ++i) {
if (A[sus[i]] == A[sus[i + 1]]) swap(A[sus[i]], B[sus[i]]);
else if (A[sus[i]] == B[sus[i + 1]]) {
swap(A[sus[i]], B[sus[i]]);
swap(A[sus[i + 1]], B[sus[i + 1]]);
} else if (B[sus[i]] == B[sus[i + 1]]) {
swap(A[sus[i + 1]], B[sus[i + 1]]);
}
assert(B[sus[i]] == A[sus[i + 1]]);
}
for (int i : sus) {
cout << A[i] + 1 << " ";
}
exit(0);
}
}
}
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];
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]) {
g[i].push_back(j);
g[j].push_back(i);
}
}
}
}
for (int v = 0; v < r; ++v) {
if (!used[v]) {
dfs(v, -1);
}
}
cout << "no";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Runtime error |
4 ms |
5332 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Too short sequence |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Too short sequence |
2 |
Incorrect |
2 ms |
2644 KB |
Wrong answer on graph without induced cycle |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2772 KB |
Too short sequence |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
3156 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
3412 KB |
Wrong answer on graph without induced cycle |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
5972 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
111 ms |
33360 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
171 ms |
92984 KB |
Wrong adjacency |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
142 ms |
6460 KB |
Too short sequence |
2 |
Correct |
136 ms |
5872 KB |
Output is correct |
3 |
Correct |
365 ms |
169504 KB |
Too short sequence |
4 |
Incorrect |
370 ms |
169460 KB |
Wrong answer on graph without induced cycle |
5 |
Halted |
0 ms |
0 KB |
- |