Submission #560686

# Submission time Handle Problem Language Result Execution time Memory
560686 2022-05-11T22:56:12 Z urosk Pipes (CEOI15_pipes) C++14
40 / 100
1055 ms 48548 KB
// __builtin_popcount(x)
// __builtin_popcountll(x)
#define here cerr<<"===========================================\n"
#include <bits/stdc++.h>
#define ld double
#define ll int
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
using namespace std;

#define maxn 100005
ll n,m;
ll dsu[maxn];
ll dsu2[maxn];
vector<ll> g[maxn];
ll low[maxn];
ll in[maxn];
vector<pll> bridge;
bool vis[maxn];
ll root(ll x,ll* dsu){
    while(x!=dsu[x]){
       dsu[x] = dsu[dsu[x]];
       x = dsu[x];
    }
    return x;
}
void upd(ll x,ll y,ll* dsu){
    x = root(x,dsu);
    y = root(y,dsu);
    dsu[y] = x;
}
bool get(ll x,ll y,ll* dsu){return root(x,dsu)==root(y,dsu);}
ll it = 1;
void dfs(ll u,ll par){
    in[u] = low[u] = it++;
    vis[u] = 1;
    bool bio = 0;
    for(ll s : g[u]){
        if(s==par&&!bio){bio = 1;continue;}
        if(!vis[s]) dfs(s,u);
        low[u] = min(low[u],low[s]);
    }
    if(u!=par&&low[u]>in[par]) bridge.pb({u,par});
}
int main(){
	ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
    cin >> n >> m;
    iota(dsu+1,dsu+n+1,1);
    iota(dsu2+1,dsu2+n+1,1);
    vector<pll> v;
    for(ll i = 1;i<=m;i++){
        ll x,y; cin >> x >> y;
        if(get(x,y,dsu)){
            if(get(x,y,dsu2)) continue;
            upd(x,y,dsu2);
        }else upd(x,y,dsu);
        g[x].pb(y);
        g[y].pb(x);
        v.pb({x,y});
    }
    for(ll i = 1;i<=n;i++) if(!vis[i]) dfs(i,i);
    for(pll p : bridge) cout<<p.fi<< " "<<p.sc<<endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3284 KB Output is correct
2 Correct 7 ms 3208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 3040 KB Output is correct
2 Correct 79 ms 3388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 148 ms 3944 KB Output is correct
2 Correct 171 ms 14684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 237 ms 5728 KB Output is correct
2 Runtime error 229 ms 19236 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 333 ms 11760 KB Output is correct
2 Runtime error 329 ms 26516 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 517 ms 13128 KB Output is correct
2 Runtime error 573 ms 21396 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 719 ms 15632 KB Output is correct
2 Runtime error 678 ms 25144 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 834 ms 15528 KB Output is correct
2 Runtime error 841 ms 32380 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1004 ms 14948 KB Output is correct
2 Runtime error 1055 ms 48548 KB Memory limit exceeded
3 Halted 0 ms 0 KB -