Submission #550204

# Submission time Handle Problem Language Result Execution time Memory
550204 2022-04-17T14:40:52 Z leaked Pipes (CEOI15_pipes) C++17
70 / 100
1091 ms 17536 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+1;
vec<pii> g[N];
//array<int,2> e[2*N];
int fup[N],in[N],tt=2;
struct dsu{
    int p[N],sz[N];
    dsu(){
        iota(p,p+N,0);
        fill(sz,sz+N,1);
    }
    int get(int v){
        return p[v]=(p[v]==v?v:get(p[v]));
    }
    bool mg(int v,int u){
        v=get(v),u=get(u);
        if(v==u) return 0;
        if(sz[v]<sz[u]) swap(v,u);
        p[u]=v;sz[v]+=sz[u];
        return 1;
    }
}x,y;
void dfs(int v,int p){
    fup[v]=in[v]=tt++;
//    for(int j=0;j<sz(g[v]);j++){

//    }
    for(auto &z : g[v]){
        if(z.s==p) continue;
        if(in[z.f]) fup[v]=(fup[v]<in[z.f]?fup[v]:in[z.f]);
        else{
            dfs(z.f,z.s);
            fup[v]=(fup[v]<fup[z.f]?fup[v]:fup[z.f]);
            if(fup[z.f]>in[v]){
                cout<<v+1<<' '<<z.f+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;
    for(int i=0;i<m;i++){
        cin>>v>>u;--v;--u;
        if(x.mg(v,u) || y.mg(v,u)){
            g[v].pb({u,i});g[u].pb({v,i});
            x.p[x.get(v)]=x.get(u);
        }
    }
    for(int i=0;i<n;i++){
        if(!in[i])
            dfs(i,i);
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4180 KB Output is correct
2 Correct 3 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4820 KB Output is correct
2 Correct 6 ms 4564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 91 ms 5480 KB Output is correct
2 Correct 95 ms 5148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 152 ms 6328 KB Output is correct
2 Correct 179 ms 5464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 248 ms 7968 KB Output is correct
2 Correct 221 ms 7176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 351 ms 14224 KB Output is correct
2 Correct 302 ms 9572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 549 ms 14944 KB Output is correct
2 Correct 509 ms 10692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 730 ms 17152 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 908 ms 17536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1091 ms 16632 KB Memory limit exceeded
2 Halted 0 ms 0 KB -