Submission #539092

# Submission time Handle Problem Language Result Execution time Memory
539092 2022-03-18T11:50:41 Z alextodoran Pipes (CEOI15_pipes) C++17
40 / 100
1051 ms 50000 KB
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = (int) 1e5;

int N, M;

struct DSU {
    int root[N_MAX + 2];
    void init () {
        iota(root + 1, root + N + 1, 1);
    }
    int findRoot (int u) {
        return (root[u] == u ? u : root[u] = findRoot(root[u]));
    }
    bool join (int u, int v) {
        u = findRoot(u);
        v = findRoot(v);
        root[u] = v;
        return u != v;
    }
};
DSU A, B;

vector <int> adj[N_MAX + 2];

void addEdge (int u, int v) {
    adj[u].push_back(v);
    adj[v].push_back(u);
}

vector <pair <int, int>> bridges;
bool seen[N_MAX + 2];
int level[N_MAX + 2];

int dfs (int u, int parent = -1) {
    int minLevel = level[u];
    seen[u] = true;
    bool par = false;
    for (int v : adj[u]) {
        if (seen[v] == false) {
            level[v] = level[u] + 1;
            minLevel = min(minLevel, dfs(v, u));
        } else if (v == parent && par == false) {
            par = true;
        } else {
            minLevel = min(minLevel, level[v]);
        }
    }
    if (parent != -1 && minLevel == level[u]) {
        bridges.push_back(make_pair(parent, u));
    }
    return minLevel;
}
void dfs () {
    for (int u = 1; u <= N; u++) {
        if (seen[u] == false) {
            dfs(u);
        }
    }
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> N >> M;
    A.init(); B.init();
    while (M--) {
        int u, v;
        cin >> u >> v;
        if (A.join(u, v) == true) {
            addEdge(u, v);
        } else if (B.join(u, v) == true) {
            addEdge(u, v);
        }
    }

    dfs();
    for (pair <int, int> e : bridges) {
        cout << e.first << " " << e.second << "\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3164 KB Output is correct
2 Correct 5 ms 3028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 2976 KB Output is correct
2 Correct 93 ms 8208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 157 ms 3644 KB Output is correct
2 Correct 186 ms 14632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 252 ms 5212 KB Output is correct
2 Runtime error 219 ms 18756 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 370 ms 10392 KB Output is correct
2 Runtime error 332 ms 25036 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 549 ms 11532 KB Output is correct
2 Runtime error 556 ms 41996 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 709 ms 13592 KB Output is correct
2 Runtime error 710 ms 50000 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 875 ms 17280 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1051 ms 29656 KB Memory limit exceeded
2 Halted 0 ms 0 KB -