답안 #393148

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
393148 2021-04-22T20:07:13 Z dolphingarlic Potemkin cycle (CEOI15_indcyc) C++14
20 / 100
371 ms 51292 KB
/*
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], stck;
int visited[100001];

void dfs(int node, int root, int parent = -1) {
    if (visited[node] == root) {
        while (stck.back() != node) {
            cout << u[stck.back()] << ' ';
            stck.pop_back();
        }
        cout << u[node];
        exit(0);
    }
    if (visited[node]) return;

    stck.push_back(node);
    visited[node] = root;
    for (int i : graph[node]) if (i != parent) dfs(i, root, 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]);
        }
    }

    for (int i = 1; i <= 2 * r; i++) if (!visited[i]) dfs(i, i);
    cout << "no";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2628 KB Output is correct
3 Correct 2 ms 2648 KB Output is correct
4 Correct 2 ms 2636 KB Output is correct
5 Correct 2 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2636 KB Repeated vertex
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 3020 KB Wrong adjacency
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 3280 KB Repeated vertex
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 4172 KB Wrong answer on graph without induced cycle
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 5284 KB Repeated vertex
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 371 ms 22276 KB Repeated vertex
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 182 ms 51292 KB Repeated vertex
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 112 ms 12188 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -