Submission #54936

# Submission time Handle Problem Language Result Execution time Memory
54936 2018-07-05T13:33:42 Z Diuven Pipes (CEOI15_pipes) C++11
20 / 100
1270 ms 14048 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=100010, inf=2e9;


int n, m;
int U[2][MX];

vector<int> G[MX];

int find(int t, int x){
    return x==U[t][x] ? x : U[t][x]=find(t,U[t][x]);
}
void unite(int t, int x, int y){
    if(find(t,x)==find(t,y)) return;
    U[t][U[t][y]]=U[t][x];
}

int up[MX], dep[MX], now;
void dfs(int v, int p){
    dep[v]=++now; up[v]=dep[v];
    for(int x:G[v]){
        if(x==p) continue;
        if(dep[x]>0) up[v]=min(up[v], dep[x]);
        else{
            dfs(x,v);
            up[v]=min(up[v], up[x]);
            if(up[x]>dep[v]) cout<<v<<' '<<x<<'\n';
        }
    }
    now--;
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n>>m;
    for(int i=1; i<=n; i++) U[0][i]=U[1][i]=i;
    for(int i=1; i<=m; i++){
        int u, v; cin>>u>>v;
        if(find(0,u)==find(0,v)){
            if(find(1,u)==find(1,v)) continue;
            unite(1,u,v);
        }
        else unite(0,u,v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    for(int i=1; i<=n; i++)
        if(dep[i]==0) dfs(i,-1);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Incorrect 3 ms 2688 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 8 ms 3200 KB Output is correct
2 Incorrect 7 ms 2944 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 99 ms 3040 KB Output is correct
2 Incorrect 95 ms 2908 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Incorrect 164 ms 3836 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 287 ms 5312 KB Output is correct
2 Correct 255 ms 4980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 421 ms 10604 KB Output is correct
2 Incorrect 384 ms 7128 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 658 ms 11864 KB Output is correct
2 Incorrect 620 ms 8952 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 900 ms 14040 KB Output is correct
2 Incorrect 833 ms 9144 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 1201 ms 14048 KB Output is correct
2 Incorrect 1059 ms 9140 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 1252 ms 13416 KB Output is correct
2 Correct 1270 ms 10824 KB Output is correct