Submission #100503

# Submission time Handle Problem Language Result Execution time Memory
100503 2019-03-11T19:48:41 Z doowey Pipes (CEOI15_pipes) C++14
100 / 100
1574 ms 13964 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;
    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);
        }
        else if(B.unite(u,v)){
            T[u].push_back(v);
            T[v].push_back(u);
        }
    }
    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 9 ms 4736 KB Output is correct
2 Correct 10 ms 4480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 129 ms 4580 KB Output is correct
2 Correct 121 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 205 ms 5204 KB Output is correct
2 Correct 245 ms 4840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 347 ms 6540 KB Output is correct
2 Correct 299 ms 6200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 506 ms 11128 KB Output is correct
2 Correct 440 ms 8144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 779 ms 12028 KB Output is correct
2 Correct 757 ms 9592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1041 ms 13936 KB Output is correct
2 Correct 995 ms 9880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1287 ms 13964 KB Output is correct
2 Correct 1304 ms 9852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1574 ms 13432 KB Output is correct
2 Correct 1477 ms 10932 KB Output is correct