Submission #100629

# Submission time Handle Problem Language Result Execution time Memory
100629 2019-03-12T23:25:16 Z doowey Pipes (CEOI15_pipes) C++14
30 / 100
5000 ms 5504 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);

mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());

const int N = (int)1e5+1;
int n1[N], n2[N];
int tin[N], low[N];
int nd[4 * N], pv[4 * N];
int las[N];
int timer;
int cnt;

void add(int a, int b){ // a -> b
    nd[cnt]=b;
    pv[cnt]=las[a];
    las[a]=cnt;
    cnt ++ ;
}

void EDGE(int a, int b){
    add(a,b);
    add(b,a);
}

int fin1(int x){
    while(n1[x] != x) x=n1[x];
    return x;
}
int fin2(int x){
    while(n2[x] != x) x=n2[x];
    return x;
}

bool merg1(int a, int b){
    a=fin1(a);
    b=fin1(b);
    if(a==b) return false;
    if((int)rnd()%2)n1[a]=b;
    else n1[b] = a;
    return true;
}
bool merg2(int a, int b){
    a=fin2(a);
    b=fin2(b);
    if(a==b) return false;
    if((int)rnd()%2)n2[a]=b;
    else n2[b]=a;
    return true;
}

void Init(){
    for(int i = 0 ; i < N ; i ++ ){
        n1[i] = i, n2[i] = i;
        tin[i] = -1, low[i] = -1;
        las[i] = -1;
    }
    for(int i = 0 ; i < 4 * N ; i ++ ){
        nd[i] = -1;
        pv[i] = -1;
    }
}

void dfs(int node, int par){
    tin[node] = timer ++ ;
    low[node] = tin[node];
    for(int j = las[node] ; j != -1 ; j = pv[j]){
        if(nd[j] == par){
            continue;
        }
        if(tin[nd[j]] != -1){
            low[node] = min(low[node], tin[nd[j]]);
        }
        else{
            dfs(nd[j], node);
            low[node] = min(low[node], low[nd[j]]);
            if(tin[node] < low[nd[j]] && fin2(node) != fin2(nd[j])){
                cout << node << " " << nd[j] << "\n";
            }
        }
    }
}

int main(){
    fastIO;
    Init();
    int n, m;
    cin >> n >> m;
    int u, v;
    for(int i = 0 ; i < m ; i ++ ){
        cin >> u >> v;
        if(merg1(u,v))
            EDGE(u, v);
        else if(merg2(u,v))
            EDGE(u, v);
    }
    for(int i =1 ; i <= n; i ++ )
        if(tin[i] == -1) dfs(i,-1);
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 6 ms 5376 KB Output is correct
2 Correct 6 ms 5504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 5496 KB Output is correct
2 Correct 14 ms 5376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2535 ms 5476 KB Output is correct
2 Correct 441 ms 5496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5052 ms 5376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5058 ms 5504 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5058 ms 5376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5043 ms 5504 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5086 ms 5376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5080 ms 5376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5040 ms 5376 KB Time limit exceeded
2 Halted 0 ms 0 KB -