Submission #851494

# Submission time Handle Problem Language Result Execution time Memory
851494 2023-09-20T01:27:43 Z Nhoksocqt1 Pipes (CEOI15_pipes) C++17
90 / 100
796 ms 22248 KB
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 100005;

vector<int> adj[MAXN];
int lab[MAXN][2], numNode, numEdge;

int root(int it, int u) {
    return (lab[u][it] == u) ? u : (lab[u][it] = root(it, lab[u][it]));
}

void dfs(int u, int p) {
    lab[u][0] = lab[u][1] = ++lab[0][0];

    bool edgep(1);
    for (int v : adj[u]) {
        if(v == p && edgep) {
            edgep = 0;
            continue;
        }

        if(!lab[v][1]) {
            dfs(v, u);
            lab[u][0] = min(lab[u][0], lab[v][0]);
            if(lab[v][0] >= lab[v][1])
                cout << u << ' ' << v << '\n';
        } else {
            lab[u][0] = min(lab[u][0], lab[v][1]);
        }
    }
}

void process() {
    cin >> numNode >> numEdge;
    for (int i = 1; i <= numNode; ++i)
        lab[i][0] = lab[i][1] = i;

    for (int i = 0; i < numEdge; ++i) {
        int u, v;
        cin >> u >> v;
        if(root(0, u) != root(0, v)) {
            lab[lab[u][0]][0] = lab[v][0];
            adj[u].push_back(v);
            adj[v].push_back(u);
        } else
            if(root(1, u) != root(1, v)) {
                lab[lab[u][1]][1] = lab[v][1];
                adj[u].push_back(v);
                adj[v].push_back(u);
            }
    }

    for (int i = 0; i <= numNode; ++i)
        lab[i][0] = lab[i][1] = 0;

    for (int i = 1; i <= numNode; ++i) {
        if(!lab[i][1])
            dfs(i, -1);
    }
}

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

    process();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3160 KB Output is correct
2 Correct 1 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3672 KB Output is correct
2 Correct 3 ms 3416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 3564 KB Output is correct
2 Correct 66 ms 3552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 4368 KB Output is correct
2 Correct 132 ms 3844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 209 ms 5968 KB Output is correct
2 Correct 169 ms 5712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 250 ms 11000 KB Output is correct
2 Correct 244 ms 6852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 410 ms 12192 KB Output is correct
2 Correct 388 ms 8804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 510 ms 14224 KB Output is correct
2 Correct 485 ms 8528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 654 ms 14160 KB Output is correct
2 Correct 581 ms 8528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 796 ms 13648 KB Output is correct
2 Runtime error 753 ms 22248 KB Memory limit exceeded
3 Halted 0 ms 0 KB -