Submission #100625

# Submission time Handle Problem Language Result Execution time Memory
100625 2019-03-12T23:10:51 Z doowey Pipes (CEOI15_pipes) C++14
100 / 100
3987 ms 8696 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+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){
    if(n1[x] == x) return x;
    return n1[x]=fin1(n1[x]);
}
int fin2(int x){
    if(n2[x] == x) return x;
    return n2[x]=fin2(n2[x]);
}

bool merg1(int a, int b){
    a=fin1(a);
    b=fin1(b);
    if(a==b) return false;
    n1[a]=b;
    return true;
}
bool merg2(int a, int b){
    a=fin2(a);
    b=fin2(b);
    if(a==b) return false;
    n2[a]=b;
    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(){
    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 5376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 5476 KB Output is correct
2 Correct 12 ms 5376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 293 ms 5452 KB Output is correct
2 Correct 286 ms 5444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 514 ms 5700 KB Output is correct
2 Correct 596 ms 5444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 869 ms 6084 KB Output is correct
2 Correct 744 ms 5824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1144 ms 7620 KB Output is correct
2 Correct 1002 ms 5700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1778 ms 8000 KB Output is correct
2 Correct 1795 ms 6732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2466 ms 8652 KB Output is correct
2 Correct 2203 ms 5828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3088 ms 8696 KB Output is correct
2 Correct 3092 ms 5832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3987 ms 8388 KB Output is correct
2 Correct 3984 ms 6976 KB Output is correct