Submission #234129

# Submission time Handle Problem Language Result Execution time Memory
234129 2020-05-23T09:04:29 Z PeppaPig Pipes (CEOI15_pipes) C++14
0 / 100
1941 ms 34264 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]); }

    bool unite(int a, int b) {
        a = find(a), b = find(b);
        if(a == b) return false;
        par[a] = b;
        return true;
    }
};

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);

    UnionFind d1, d2;
    for(int i = 1, a, b; i <= m; i++) {
        scanf("%d %d", &a, &b);
        bool valid = d1.unite(a, b);
        if(valid || (!valid && d2.unite(a, b)))
            g[a].emplace_back(b), g[b].emplace_back(a);
    }
    tarjan(1, 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:50: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:39: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:44:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1152 KB Output is correct
2 Incorrect 5 ms 1152 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 1664 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 165 ms 7032 KB Output is correct
2 Incorrect 169 ms 6744 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Incorrect 284 ms 11896 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 476 ms 19868 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 636 ms 29560 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 966 ms 29920 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1343 ms 34264 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1590 ms 24696 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1941 ms 26588 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -