#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
3 ms |
4940 KB |
Output is correct |
5 |
Correct |
3 ms |
4940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5324 KB |
Output is correct |
2 |
Correct |
5 ms |
5452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
5724 KB |
Output is correct |
2 |
Correct |
7 ms |
5708 KB |
Output is correct |
3 |
Correct |
12 ms |
7620 KB |
Output is correct |
4 |
Correct |
14 ms |
7656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
6860 KB |
Output is correct |
2 |
Correct |
10 ms |
6988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
95 ms |
22736 KB |
Output is correct |
2 |
Correct |
32 ms |
9824 KB |
Output is correct |
3 |
Correct |
109 ms |
22768 KB |
Output is correct |
4 |
Correct |
33 ms |
9680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
51092 KB |
Output is correct |
2 |
Correct |
123 ms |
55236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
187 ms |
9552 KB |
Output is correct |
2 |
Correct |
180 ms |
9284 KB |
Output is correct |
3 |
Correct |
213 ms |
90964 KB |
Output is correct |
4 |
Correct |
272 ms |
90956 KB |
Output is correct |