Submission #100504

# Submission time Handle Problem Language Result Execution time Memory
100504 2019-03-11T19:52:17 Z doowey Pipes (CEOI15_pipes) C++14
100 / 100
1560 ms 13936 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 9;

struct DSU{
    int pi[N];
    int sz[N];
    int fin(int x){
        while(x!=pi[x]){
            x=pi[x];
        }
        return x;
    }
    bool unite(int a, int b){
        a = fin(a);
        b = fin(b);
        if(a==b)
            return false;
        if(sz[a] > sz[b])
            swap(a, b);
        sz[b] += sz[a];
        pi[a] = b;
        return true;
    }
    void Init(){
        for(int i = 0 ;i  < N ; i ++ ){
            pi[i] = i;
            sz[i] = 1;
        }
    }
};

DSU A, B;

vector<int> T[N];

int tin[N];
int low[N];
int timer;

bool vis[N];

void dfs(int node, int par){
    vis[node] = true;
    tin[node] = timer ++ ;
    low[node] = tin[node];
    for(auto x : T[node]){
        if(x == par){
            continue;
        }
        if(vis[x]){
            low[node] = min(low[node], tin[x]);
        }
        else{
            dfs(x, node);
            low[node] = min(low[node], low[x]);
            if(tin[node] < low[x] && B.fin(x) != B.fin(node)){
                cout << x << " " << node << "\n";
            }
        }
    }
}



int main(){
    fastIO;
    A.Init();
    B.Init();
    int n, m;
    cin >> n >> m;
    int u, v;
    int cnt = 0;
    for(int i = 0 ; i < m ; i ++ ){
        cin >> u >> v;
        if(A.unite(u,v)){
            T[u].push_back(v);
            T[v].push_back(u);
            cnt += 2 ;
        }
        else if(B.unite(u,v)){
            T[u].push_back(v);
            T[v].push_back(u);
            cnt += 2;
        }
    }
    assert(cnt <= (int)4e5);
    for(int i = 1; i <= n; i ++ )
        if(!vis[i])dfs(i,-1);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4224 KB Output is correct
2 Correct 5 ms 4224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4736 KB Output is correct
2 Correct 8 ms 4528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 4572 KB Output is correct
2 Correct 114 ms 4472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 199 ms 5244 KB Output is correct
2 Correct 234 ms 4812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 335 ms 6552 KB Output is correct
2 Correct 289 ms 6240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 485 ms 11100 KB Output is correct
2 Correct 462 ms 8184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 802 ms 12036 KB Output is correct
2 Correct 751 ms 9704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1098 ms 13936 KB Output is correct
2 Correct 1018 ms 10056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1296 ms 13928 KB Output is correct
2 Correct 1236 ms 9860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1560 ms 13476 KB Output is correct
2 Correct 1439 ms 11128 KB Output is correct