Submission #851489

# Submission time Handle Problem Language Result Execution time Memory
851489 2023-09-20T01:20:34 Z Nhoksocqt1 Pipes (CEOI15_pipes) C++17
40 / 100
810 ms 65536 KB
#include<bits/stdc++.h>
using namespace std;

#define inf 0x3f3f3f3f
#define sz(x) int((x).size())
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;

template<class X, class Y>
	inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);}
template<class X, class Y>
	inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Random(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

const int MAXN = 100005;

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

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

bool join(int it, int u, int v) {
    u = root(it, u), v = root(it, v);
    if(u == v)
        return (false);

    if(lab[u][it] > lab[v][it])
        swap(u, v);

    lab[u][it] += lab[v][it];
    lab[v][it] = u;
    return (true);
}

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

    int edgep(1);
    for (int it = 0; it < sz(adj[u]); ++it) {
        int v(adj[u][it]);
        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] = -1;

    for (int i = 0; i < numEdge; ++i) {
        int u, v;
        cin >> u >> v;
        if(join(0, u, v)) {
            adj[u].push_back(v);
            adj[v].push_back(u);
        } else
            if(join(1, u, v)) {
                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);
    }
}

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 1 ms 3160 KB Output is correct
2 Correct 1 ms 3672 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 68 ms 3664 KB Output is correct
2 Correct 68 ms 8804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 4432 KB Output is correct
2 Correct 145 ms 15184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 189 ms 5972 KB Output is correct
2 Runtime error 171 ms 19284 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 259 ms 23888 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 391 ms 45204 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 563 ms 58156 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 636 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 810 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -