Submission #527145

# Submission time Handle Problem Language Result Execution time Memory
527145 2022-02-17T02:41:25 Z chicken337 Pipes (CEOI15_pipes) C++14
90 / 100
926 ms 62220 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
 
int v, e, ID = 0;
int num[MAXN], low[MAXN];
vector<int> adj[MAXN];

struct UFDS{
    int p[MAXN];
    char r[MAXN];
    UFDS(){
        for(int i = 0; i < v; i ++)
            p[i] = i, r[i] = 0;
    }
    int root(int x){
        if(p[x] == x) return x;
        return p[x] = root(p[x]);
    }
    bool connected(int x, int y){
        return root(x) == root(y);
    }
    void connect(int x, int y){
        x = root(x), y = root(y);
        if(r[x] < r[y]) swap(x, y);
        if(r[x] == r[y]) r[x] ++;
        p[y] = x;
    }
};
 
void dfs(int x, int par){
    num[x] = low[x] = ID ++;
    for(int nxt : adj[x]){
        if(num[nxt] == -1){
            dfs(nxt, x);
            if(num[x] < low[nxt])
                cout << x+1 << ' ' << nxt+1 << '\n';
            low[x] = min(low[x], low[nxt]);
        } else if(nxt != par){
            low[x] = min(low[x], num[nxt]);
        } else par = -1;
    }
}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
 
    cin >> v >> e; int a, b;
    UFDS ua = UFDS();
    UFDS ub = UFDS();
    memset(num, -1, sizeof num);
    for(int i = 0; i < e; i ++){
        cin >> a >> b;
        if(!ua.connected(a-1, b-1)){
            adj[a-1].push_back(b-1);
            adj[b-1].push_back(a-1);
            ua.connect(a-1, b-1);
        } else if(!ub.connected(a-1, b-1)){
            adj[a-1].push_back(b-1);
            adj[b-1].push_back(a-1);
            ub.connect(a-1, b-1);
        }
    }
    for(int i = 0; i < v; i ++)
        if(num[i] == -1)
            dfs(i, -1);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4028 KB Output is correct
2 Correct 2 ms 4044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4564 KB Output is correct
2 Correct 8 ms 4300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 5684 KB Output is correct
2 Correct 91 ms 5960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 138 ms 6620 KB Output is correct
2 Correct 164 ms 5772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 244 ms 8692 KB Output is correct
2 Correct 202 ms 6960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 310 ms 12104 KB Output is correct
2 Correct 273 ms 7872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 482 ms 13160 KB Output is correct
2 Correct 511 ms 9968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 607 ms 15644 KB Output is correct
2 Correct 612 ms 9356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 862 ms 15852 KB Output is correct
2 Runtime error 816 ms 62220 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 926 ms 14748 KB Output is correct
2 Correct 896 ms 11844 KB Output is correct