#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<int> st;
int used[2][M];
void dfs(int t, int v, pair<int, int> p) {
used[t][v] = 1;
st.emplace_back(C[t][v]);
for (auto to: g[t][v]) {
if (to != p) {
if (used[to.first][to.second] == 1) {
cout << C[to.first][to.second] + 1 << " ";
int lst = C[to.first][to.second];
int wow = 0;
while (true) {
auto u = st.back();
cout << u + 1 << " ";
if (wow && e[u][lst]) {
break;
}
++wow;
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});
}
}
}
used[t][v] = 2;
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 |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
5076 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
5076 KB |
Output is correct |
2 |
Correct |
2 ms |
5000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5588 KB |
Output is correct |
2 |
Correct |
4 ms |
5760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
5828 KB |
Output is correct |
2 |
Correct |
7 ms |
5844 KB |
Output is correct |
3 |
Correct |
15 ms |
9572 KB |
Output is correct |
4 |
Correct |
14 ms |
9684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8276 KB |
Output is correct |
2 |
Correct |
11 ms |
8532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
36148 KB |
Output is correct |
2 |
Correct |
26 ms |
12192 KB |
Output is correct |
3 |
Correct |
105 ms |
36288 KB |
Output is correct |
4 |
Correct |
42 ms |
12240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
135 ms |
95180 KB |
Output is correct |
2 |
Correct |
162 ms |
103328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
115 ms |
9720 KB |
Output is correct |
2 |
Correct |
111 ms |
9632 KB |
Output is correct |
3 |
Correct |
284 ms |
172496 KB |
Output is correct |
4 |
Correct |
322 ms |
172564 KB |
Output is correct |