Submission #379784

# Submission time Handle Problem Language Result Execution time Memory
379784 2021-03-19T09:41:43 Z alirezasamimi100 Pipes (CEOI15_pipes) C++17
90 / 100
1388 ms 18208 KB
#include <bits/stdc++.h>
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
/*#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma")*/
using namespace std;
using ll = long long int;
#define F first
#define S second
#define pb push_back
#define lc v<<1
#define rc v<<1|1
#define fast_io ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int N=1e5+10,LN=20,M=1e5+10,SQ=450,inf=1e9;
const ll INF=1e18;
const int MH=1000696969,MOD=1000000007 /*998244353*/;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using pll=pair<ll,ll>;
using pii=pair<int,int>;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
ll pow(ll x, ll y, ll mod){
    ll ans=1;
    while (y != 0) {
        if (y & 1) ans = ans * x % mod;
        y >>= 1;
        x = x * x % mod;
    }
    return ans;
}
int n,q,p[2][N],m,dp[N],h[N];
bool f[N];
vector<int> adj[N];
ll gp(int c, int x){
    return p[c][x]?p[c][x]=gp(c,p[c][x]):x;
}
bool uni(int c, int v, int u){
    v=gp(c,v);
    u=gp(c,u);
    if(v==u) return false;
    p[c][u]=v;
    return true;
}
void dfs(int v, int pr){
    f[v]=1;
    dp[v]=h[v];
    for(int u : adj[v]){
        if(!f[u]) h[u]=h[v]+1,dfs(u,v),dp[v]=min(dp[u],dp[v]);
    }
    ll x=1;
    for(int u : adj[v]){
        if(u==pr && x) x--;
        else dp[v]=min(dp[v],h[u]);
    }
    if(dp[v]==h[v] && pr) cout << v << ' ' << pr << '\n';
}
int main(){
    fast_io;
    cin >> n >> q;
    while(q--){
        int v,u;
        cin >> v >> u;
        if(uni(0,v,u) || uni(1,v,u)) adj[v].pb(u),adj[u].pb(v);
    }
    for(int i=1; i<=n; i++) if(!f[i]) dfs(i,0);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3308 KB Output is correct
2 Correct 6 ms 3052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 114 ms 3192 KB Output is correct
2 Correct 132 ms 2928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 207 ms 3948 KB Output is correct
2 Correct 247 ms 3436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 328 ms 5740 KB Output is correct
2 Correct 285 ms 5356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 460 ms 11396 KB Output is correct
2 Correct 401 ms 7404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 699 ms 12752 KB Output is correct
2 Correct 708 ms 9524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 949 ms 15212 KB Output is correct
2 Correct 957 ms 16364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1123 ms 15132 KB Output is correct
2 Runtime error 1069 ms 18208 KB Memory limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 1388 ms 14456 KB Output is correct
2 Correct 1363 ms 11196 KB Output is correct