Submission #397309

# Submission time Handle Problem Language Result Execution time Memory
397309 2021-05-01T21:12:29 Z Bitmasking Pipes (CEOI15_pipes) C++17
90 / 100
1375 ms 16736 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define f(i,a,b) for( ll i = a; i < b ; i++ )
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(ini) (ll) __builtin_popcountll(x)
#define todo(y,val) all_of(all(y),[&val](ll x) {return (x == ((ll)val));})
#define nada(y,val) none_of(all(y),[&val](ll x) {return (x == ((ll)val));})
#define algu(y,val) any_of(all(y),[&val](ll x) {return (x == ((ll)val));})
#define cuantos(a,x) count(all(a),x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ller ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is " << (x) <<"\n"
#define test ll deftestcases;cin>>deftestcases;while(deftestcases--)
#define PI acos(-1)
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii;
typedef vector<ll>  vi;
typedef vector<ii> vii;
template<class T> using ordered_set =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ;
const ll inf = 2e18;
const ll mod = 1e9+7;   
const ll MAX = 1e5+10;
 
vi adj[MAX];
ll dspar[2][MAX];
ll tin[MAX],low[MAX];
ll timer = 0;

ll finds(ll aux,ll v){
    if(v == dspar[aux][v]) return v;
    return dspar[aux][v] = finds(aux,dspar[aux][v]);
}

bool uni(ll aux,ll a,ll b){
    ll u = a,v = b;
    a = finds(aux,a),b = finds(aux,b);
    if(a==b) return 0;
    dspar[aux][b] = a;
    adj[u].pb(v);
    adj[v].pb(u);
    return 1;
}
void is_bridge(ll u,ll v){
    cout<<u<<" "<<v<<"\n";
}
bool check(ll u,ll v){
    return finds(1,u)==finds(1,v);
}
void dfs(ll u,ll par = -1){
    tin[u] = low[u] = timer++;
    for(auto v : adj[u]){
        if(v == par) continue;
        if(tin[v]!=-1) low[u] = min(low[u],tin[v]);
        else{
            dfs(v,u);
            if(low[v]>tin[u] && !(check(u,v))) is_bridge(u,v);
            low[u] = min(low[u],low[v]);
        }
    }
}
 
void init_bridges(ll n,ll m){
    timer = 0;
    f(i,0,n+6){
        tin[i]=low[i]=-1;
        dspar[0][i] = dspar[1][i] = i;
    }
    f(i,0,m){
        ll u,v;cin>>u>>v;
        if(!uni(0,u,v)){
            uni(1,u,v);
        }
    }
    f(i,1,n+1){
        if(tin[i]==-1) dfs(i);
    }
}
 
 
int main(){
    fastio;
    timer = 0;
    ll n,m;cin>>n>>m;
    init_bridges(n,m);
    return 0;  
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3148 KB Output is correct
2 Correct 6 ms 3020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 111 ms 3140 KB Output is correct
2 Correct 113 ms 3020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 185 ms 3856 KB Output is correct
2 Correct 218 ms 3572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 322 ms 5740 KB Output is correct
2 Correct 286 ms 5444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 453 ms 11736 KB Output is correct
2 Correct 399 ms 9428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 684 ms 13128 KB Output is correct
2 Correct 685 ms 11920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 943 ms 15456 KB Output is correct
2 Correct 893 ms 15300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1115 ms 15448 KB Output is correct
2 Runtime error 1078 ms 16736 KB Memory limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 1321 ms 14792 KB Output is correct
2 Correct 1375 ms 12612 KB Output is correct