Submission #550208

# Submission time Handle Problem Language Result Execution time Memory
550208 2022-04-17T14:58:23 Z leaked Pipes (CEOI15_pipes) C++17
100 / 100
1130 ms 13920 KB
#include <bits/stdc++.h>

#define f first
#define s second
#define m_p make_pair
#define vec vector
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pw(x) (1LL<<(x))
#define sz(x) (int)(x).size()

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);}
template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);}
const int N=1e5;
const int M=(N-1)*2;
int* g[N];
int ii[M],ij[M],e;
int siz[N],x[N],y[N],tt=2;

int get(int *p,int v){
    return (p[v]<0?v:p[v]=get(p,p[v]));
}
bool mg(int *p,int v,int u){
    v=get(p,v);u=get(p,u);
    if(v==u) return 0;
    if(p[v]<p[u]) swap(v,u);
    p[u]=v;--p[v];
    return 1;
}

void dfs(int v,int p){
    x[v]=y[v]=tt++;
    int j,u;
    while(siz[v]--){
        j=g[v][siz[v]];
        u=ii[j]^ij[j]^v;
        if(j==p) continue;
        if(x[u]) x[v]=(x[v]<y[u]?x[v]:y[u]);
        else{
            dfs(u,j);
            x[v]=(x[v]<x[u]?x[v]:x[u]);
//            cerr<<v<<' '<<u<<' '<<
            if(x[u]>y[v]){
                cout<<v+1<<' '<<u+1<<'\n';
            }
        }
    }
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,m;
    int v,u;
    cin>>n>>m;
    fill(x,x+N,-1);fill(y,y+N,-1);
    for(int i=0;i<m;i++){
        cin>>v>>u;--v;--u;
        if(e!=2*(n-1) && (mg(x,v,u) || mg(y,v,u))){
            ii[e]=v;ij[e++]=u;
            ++siz[v];++siz[u];
        }
    }
    fill(x,x+N,0);fill(y,y+N,0);
    for(int i=0;i<n;i++)
        g[i]=new int[siz[i]],siz[i]=0;
    for(int i=0;i<e;i++)
        g[ii[i]][siz[ii[i]]++]=i,g[ij[i]][siz[ij[i]]++]=i;
    for(int i=0;i<n;i++){
        if(!x[i])
            dfs(i,i);
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1748 KB Output is correct
2 Correct 4 ms 1500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 2168 KB Output is correct
2 Correct 97 ms 1800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 151 ms 2836 KB Output is correct
2 Correct 183 ms 2224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 246 ms 4784 KB Output is correct
2 Correct 230 ms 4244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 354 ms 10480 KB Output is correct
2 Correct 323 ms 5964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 481 ms 11748 KB Output is correct
2 Correct 561 ms 8192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 647 ms 13532 KB Output is correct
2 Correct 634 ms 8092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 871 ms 13920 KB Output is correct
2 Correct 841 ms 8376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 932 ms 13076 KB Output is correct
2 Correct 1130 ms 12688 KB Output is correct