답안 #527702

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
527702 2022-02-18T04:01:41 Z beepbeepsheep Pipes (CEOI15_pipes) C++17
100 / 100
1014 ms 14876 KB
#include <bits/stdc++.h>
using namespace std;

#define ll int
#define ii pair<ll,ll>
#define endl '\n'
const ll inf=1e15;
const ll mod=1e9+7;
const ll maxn=1e5+5;

vector<ll> adj[maxn];
ll cnt[maxn],depth[maxn],low[maxn];
ll par[maxn][2];
int root(ll x, ll l){
    if (par[x][l]==x) return x;
    return par[x][l]=root(par[x][l],l);
}
bool connect(ll a, ll b, ll l){
    if (root(a,l)==root(b,l)) return 0;
    par[root(a,l)][l]=root(b,l);
    return 1;
}
void dfs(ll node, ll p){
    bool seen=0;
    for (auto &u:adj[node]){
        if (u==p && !seen){
            seen=1;
            continue;
        }
        if (!depth[u]){
            depth[u]=depth[node]+1;
            dfs(u,node);
            if (low[u]>depth[node]){
                cout<<node<<' '<<u<<endl;
            }
            low[node]=min(low[node],low[u]);
        } else{
            low[node]=min(low[node],depth[u]);
        }
    }
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,e,a,b;
    cin>>n>>e;
    for (int i=0;i<maxn;i++) low[i]=inf;
    for (int i=0;i<maxn;i++){
        par[i][0]=i;
        par[i][1]=i;
    }
    for (int i=0;i<e;i++){
        cin>>a>>b;
        if (connect(a,b,0) || connect(a,b,1)){
            adj[a].emplace_back(b);
            adj[b].emplace_back(a);
        }
    }
    for (int i=1;i<=n;i++){
        if (depth[i]) continue;
        depth[i]=1;
        dfs(i,-1);
    }
    return 0;
}

Compilation message

pipes.cpp:7:14: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+15' to '2147483647' [-Woverflow]
    7 | const ll inf=1e15;
      |              ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3788 KB Output is correct
2 Correct 2 ms 3788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4300 KB Output is correct
2 Correct 7 ms 4044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 4116 KB Output is correct
2 Correct 84 ms 3968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 146 ms 4804 KB Output is correct
2 Correct 166 ms 4652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 278 ms 6452 KB Output is correct
2 Correct 201 ms 5848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 338 ms 11752 KB Output is correct
2 Correct 291 ms 7552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 497 ms 12712 KB Output is correct
2 Correct 486 ms 9480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 679 ms 14876 KB Output is correct
2 Correct 617 ms 9144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 839 ms 14872 KB Output is correct
2 Correct 859 ms 9124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1014 ms 14284 KB Output is correct
2 Correct 915 ms 11052 KB Output is correct