Submission #245343

# Submission time Handle Problem Language Result Execution time Memory
245343 2020-07-06T05:19:21 Z lyc Pipes (CEOI15_pipes) C++14
90 / 100
1349 ms 19448 KB
#include <iostream>
#include <vector>
using namespace std;

#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)

const int mxN = 1e5+5;
int N, M;
int E[2*mxN], ne;
vector<int> al[mxN];

struct UFDS {
    int p[mxN], s[mxN];
    UFDS() { FOR(i,1,N) p[i] = i, s[i] = 1; }
    int finds(int i) { return (p[i] == i) ? i : (p[i] = finds(p[i])); }
    bool unions(int i, int j) {
        int x = finds(i), y = finds(j);
        if (x == y) return 0;
        if (s[x] < s[y]) swap(x,y);
        p[y] = x, s[x] += s[y];
        return 1;
    }
};

int num[mxN], low[mxN], cnt;
void dfs(int u, int p) {
    num[u] = low[u] = cnt++;
    for (int e : al[u]) {
        if (e == p) continue;
        int v = E[e]^u;
        if (num[v] == -1) {
            dfs(v,e);
            low[u] = min(low[u],low[v]);
            if (low[v] > num[u]) cout << u << ' ' << v << '\n';
        } else low[u] = min(low[u],num[v]);
    }
}

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

    cin >> N >> M;
    UFDS UF[2];
    ne = 0;
    FOR(i,1,M){
        int U, V; cin >> U >> V;
        FOR(j,0,1){
            if (UF[j].unions(U,V)) {
                al[U].push_back(ne);
                al[V].push_back(ne);
                E[ne++] = U^V;
                break;
            }
        }
    }

    FOR(i,1,N) num[i] = -1;
    cnt = 0;
    FOR(i,1,N) if (num[i] == -1) dfs(i,-1);
}

# Verdict Execution time Memory Grader output
1 Correct 6 ms 2688 KB Output is correct
2 Correct 6 ms 2560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 3328 KB Output is correct
2 Correct 9 ms 3072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 3192 KB Output is correct
2 Correct 106 ms 3072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 164 ms 3960 KB Output is correct
2 Correct 197 ms 14840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 298 ms 5752 KB Output is correct
2 Runtime error 271 ms 19448 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
# Verdict Execution time Memory Grader output
1 Correct 456 ms 11772 KB Output is correct
2 Correct 390 ms 8312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 705 ms 13180 KB Output is correct
2 Correct 679 ms 10104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 936 ms 15608 KB Output is correct
2 Correct 873 ms 14624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1185 ms 15656 KB Output is correct
2 Correct 1102 ms 10744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1349 ms 14904 KB Output is correct
2 Correct 1340 ms 12148 KB Output is correct