답안 #234130

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
234130 2020-05-23T09:08:25 Z PeppaPig Pipes (CEOI15_pipes) C++14
0 / 100
2172 ms 30968 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

struct UnionFind {
    int par[N];

    UnionFind() { iota(par, par + N, 0); }

    int find(int x) { return par[x] = x == par[x] ? x : find(par[x]); }

    void unite(int a, int b) {
        a = find(a), b = find(b);
        if(a == b) return;
        par[a] = b;
    }
} d1, d2;

int n, m;
vector<vector<int> > g;
vector<int> pre, low, l, r;

void tarjan(int u, int p) {
    static int idx = 0;
    pre[u] = low[u] = ++idx;
    for(int v : g[u]) if(v != p) {
        if(!pre[v]) {
            tarjan(v, u);
            low[u] = min(low[u], low[v]);
            if(low[v] > pre[u]) l.emplace_back(u), r.emplace_back(v);
        } else low[u] = min(low[u], pre[v]);
    }
}

int main() {
    scanf("%d %d", &n, &m);
    g.resize(n + 1), pre.resize(n + 1), low.resize(n + 1);

    for(int i = 1, a, b; i <= m; i++) {
        scanf("%d %d", &a, &b);
        if(d1.find(a) != d1.find(b)) {
            d1.unite(a, b);
            g[a].emplace_back(b), g[b].emplace_back(a);
        } else if(d2.find(a) != d2.find(b)) {
            d2.unite(a, b);
            g[a].emplace_back(b), g[b].emplace_back(a);
        }
    }
    for(int i = 1; i <= n; i++) if(!pre[i]) tarjan(i, 0);
    for(int i = 0; i < l.size(); i++) printf("%d %d\n", l[i], r[i]);

    return 0;
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:52:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < l.size(); i++) printf("%d %d\n", l[i], r[i]);
                    ~~^~~~~~~~~~
pipes.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
pipes.cpp:42:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1152 KB Output is correct
2 Incorrect 5 ms 1152 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 1664 KB Output is correct
2 Incorrect 10 ms 1536 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Correct 164 ms 1888 KB Output is correct
2 Incorrect 163 ms 1760 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Incorrect 294 ms 2484 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 499 ms 3960 KB Output is correct
2 Runtime error 417 ms 17412 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# 결과 실행 시간 메모리 Grader output
1 Correct 679 ms 8928 KB Output is correct
2 Runtime error 629 ms 24696 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# 결과 실행 시간 메모리 Grader output
1 Correct 1078 ms 10104 KB Output is correct
2 Runtime error 1031 ms 29816 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# 결과 실행 시간 메모리 Grader output
1 Correct 1426 ms 12152 KB Output is correct
2 Runtime error 1376 ms 29484 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# 결과 실행 시간 메모리 Grader output
1 Correct 1738 ms 12536 KB Output is correct
2 Runtime error 1689 ms 30968 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# 결과 실행 시간 메모리 Grader output
1 Correct 2172 ms 11748 KB Output is correct
2 Runtime error 2025 ms 27788 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)