#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ii pair<int, int>
#define f first
#define s second
#define vii vector<ii>
vii adj[1000];
bool conn[1000][1000];
ii edges[200000];
vi adj2[200000];
bool vis[200000], active[200000];
vector<int> S;
void dfs(int u, int p) {
if (active[u]) {
while (true) {
int x = S.back(); S.pop_back();
cout << edges[x].s+1 << " ";
if (x == u) break;
}
cout << endl;
exit(0);
}
if (vis[u]) return;
vis[u] = true;
active[u] = true;
S.push_back(u);
for (auto v : adj2[u]) {
if (v != p) dfs(v, u);
}
S.pop_back();
active[u] = false;
}
int main() {
int n, r; cin >> n >> r;
for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) conn[i][j] = false;
for (int i = 0; i < r; i++) {
int a, b; cin >> a >> b; --a; --b;
conn[a][b] = true;
conn[b][a] = true;
edges[2*i] = {a,b};
edges[2*i+1] = {b,a};
adj[a].push_back({b,2*i});
adj[b].push_back({a,2*i+1});
}
for (int i = 0; i < 2*r; i++) {
vis[i] = active[i] = false;
int a = edges[i].f, b = edges[i].s;
for (auto v : adj[b]) {
if (v.f == a || conn[a][v.f]) continue;
adj2[i].push_back(v.s);
}
}
for (int i = 0; i < 2*r; i++) {
if (!vis[i]) dfs(i, i);
}
cout << "no" << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4992 KB |
Output is correct |
2 |
Correct |
7 ms |
4992 KB |
Output is correct |
3 |
Correct |
7 ms |
4992 KB |
Output is correct |
4 |
Correct |
7 ms |
4992 KB |
Output is correct |
5 |
Correct |
7 ms |
4992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5120 KB |
Output is correct |
2 |
Correct |
7 ms |
5120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
5248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
5376 KB |
Output is correct |
2 |
Correct |
10 ms |
5504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
5760 KB |
Output is correct |
2 |
Correct |
11 ms |
5760 KB |
Output is correct |
3 |
Correct |
17 ms |
7680 KB |
Output is correct |
4 |
Correct |
19 ms |
7680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
6960 KB |
Output is correct |
2 |
Correct |
15 ms |
7040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
107 ms |
22776 KB |
Output is correct |
2 |
Correct |
40 ms |
9872 KB |
Output is correct |
3 |
Correct |
122 ms |
22776 KB |
Output is correct |
4 |
Correct |
41 ms |
9848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
93 ms |
51256 KB |
Output is correct |
2 |
Correct |
131 ms |
55288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
174 ms |
9720 KB |
Output is correct |
2 |
Correct |
165 ms |
10008 KB |
Output is correct |
3 |
Correct |
218 ms |
91512 KB |
Output is correct |
4 |
Correct |
273 ms |
91512 KB |
Output is correct |