/*
CEOI 2016 Potemkin Cycle
- Let each edge (u, v) represent a node (uv) in graph H
- There is an edge between (uv) and (vw) in H iff (uw) doesn't exist
- This means that there are no cycles of length 3 in H
- We can construct H in O(NR) time
- An answer exists iff a cycle exists in H; run DFS to find a cycle
*/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int u[200001], v[200001], adj[1001][1001];
vector<int> graph[100001];
int prv[100001];
void dfs(int node, int parent = -1) {
prv[node] = parent;
for (int i : graph[node]) if (i != parent) {
if (prv[i]) {
vector<int> edges;
int curr = node;
while (curr != prv[i]) {
edges.push_back(curr);
curr = prv[curr];
}
int m = edges.size();
for (int j = 0; j < m; j++) cout << u[j];
exit(0);
} else dfs(i, node);
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, r;
cin >> n >> r;
for (int i = 1; i <= r; i++) {
cin >> u[i] >> v[i];
u[i + r] = v[i], v[i + r] = u[i];
adj[u[i]][v[i]] = i, adj[v[i]][u[i]] = i + r;
}
for (int i = 1; i <= 2 * r; i++) {
for (int j = 1; j <= n; j++) if (j != u[i]) {
if (adj[v[i]][j] && !adj[u[i]][j]) {
graph[i].push_back(adj[v[i]][j]);
graph[adj[v[i]][j]].push_back(i);
}
}
}
for (int i = 1; i <= 2 * r; i++) if (!prv[i]) dfs(i);
cout << "no";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2636 KB |
Expected integer, but "0123" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2640 KB |
Expected integer, but "01010118" found |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2664 KB |
Expected integer, but "033999910" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
3020 KB |
Expected integer, but "02525414141" found |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
3532 KB |
Expected integer, but "0292929" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
14 ms |
4316 KB |
Wrong answer on graph without induced cycle |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
6800 KB |
Expected integer, but "0212121" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
454 ms |
36200 KB |
Expected integer, but "0959595" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
351 ms |
96600 KB |
Expected integer, but "0244244244" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
39 ms |
11716 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |