Submission #71366799


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5+7;
vector<int> G[N];
int B[N],Y[N],P[N],timer = 0,tin[N],tmin[N];
void dfs(int v,int par){
    tin[v] = tmin[v] = ++timer;
    B[v] = par;
    Y[v] = v;
    P[v] = par;
    for(int to:G[v]){
        if (to==par){
            continue;
        }
        if (tin[to]!=0){
            if (tmin[v]>tin[to]){
                tmin[v] = tin[to];
                Y[v] = to;
            }
        }
        else{
            dfs(to,v);
            if (tmin[v]>tmin[to]){
                tmin[v] = tmin[to];
                Y[v] = to;
            }
        }
    }
    // if Y[v]==v - bad case

}
void solve(){
    int n,m;
    cin>>n>>m;
    for(int i = 0;i<m;i+=1){
        int u,v;
        cin>>u>>v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(1,1);
    int x = 2;
    while(x!=1){
        Y[P[x]] = x;
        x = P[x];
    }
    for(int i = 1;i<=n;i+=1){
        if (Y[i]==i && i!=2){
            cout<<"No\n";
            return;
        }
    }
    cout<<"Yes\n";
    cout<<Y[1]<<'\n';
    cout<<B[2]<<'\n';
    for(int i = 3;i<=n;i+=1){
        cout<<B[i]<<' '<<Y[i]<<'\n';
    }
}  
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int tt = 1;
    while(tt--){
        solve();
    }
}

Submission Info

Submission Time
Task D - Michishirube
User KULIKOLD
Language C++23 (GCC 15.2.0)
Score 700
Code Size 1374 Byte
Status AC
Exec Time 94 ms
Memory 33424 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 2
AC × 42
Set Name Test Cases
Sample 00-sample-001.txt, 00-sample-002.txt
All 00-sample-001.txt, 00-sample-002.txt, 01-non_bridge_yes-001.txt, 01-non_bridge_yes-002.txt, 01-non_bridge_yes-003.txt, 01-non_bridge_yes-004.txt, 01-non_bridge_yes-005.txt, 02-less_bridge_yes-001.txt, 02-less_bridge_yes-002.txt, 02-less_bridge_yes-003.txt, 02-less_bridge_yes-004.txt, 02-less_bridge_yes-005.txt, 02-less_bridge_yes-006.txt, 02-less_bridge_yes-007.txt, 02-less_bridge_yes-008.txt, 02-less_bridge_yes-009.txt, 02-less_bridge_yes-010.txt, 03-many_bridge_yes-001.txt, 03-many_bridge_yes-002.txt, 03-many_bridge_yes-003.txt, 03-many_bridge_yes-004.txt, 03-many_bridge_yes-005.txt, 03-many_bridge_yes-006.txt, 03-many_bridge_yes-007.txt, 03-many_bridge_yes-008.txt, 03-many_bridge_yes-009.txt, 03-many_bridge_yes-010.txt, 04-small_yes-001.txt, 04-small_yes-002.txt, 04-small_yes-003.txt, 04-small_yes-004.txt, 04-small_yes-005.txt, 05-no-001.txt, 05-no-002.txt, 05-no-003.txt, 05-no-004.txt, 05-no-005.txt, 05-no-006.txt, 05-no-007.txt, 05-no-008.txt, 05-no-009.txt, 05-no-010.txt
Case Name Status Exec Time Memory
00-sample-001.txt AC 2 ms 3652 KiB
00-sample-002.txt AC 2 ms 3528 KiB
01-non_bridge_yes-001.txt AC 90 ms 33424 KiB
01-non_bridge_yes-002.txt AC 76 ms 18372 KiB
01-non_bridge_yes-003.txt AC 75 ms 21452 KiB
01-non_bridge_yes-004.txt AC 77 ms 17280 KiB
01-non_bridge_yes-005.txt AC 73 ms 19412 KiB
02-less_bridge_yes-001.txt AC 84 ms 20812 KiB
02-less_bridge_yes-002.txt AC 78 ms 19728 KiB
02-less_bridge_yes-003.txt AC 82 ms 20344 KiB
02-less_bridge_yes-004.txt AC 77 ms 18888 KiB
02-less_bridge_yes-005.txt AC 75 ms 19496 KiB
02-less_bridge_yes-006.txt AC 82 ms 20368 KiB
02-less_bridge_yes-007.txt AC 84 ms 21976 KiB
02-less_bridge_yes-008.txt AC 81 ms 20592 KiB
02-less_bridge_yes-009.txt AC 83 ms 21068 KiB
02-less_bridge_yes-010.txt AC 77 ms 19524 KiB
03-many_bridge_yes-001.txt AC 87 ms 32624 KiB
03-many_bridge_yes-002.txt AC 90 ms 33380 KiB
03-many_bridge_yes-003.txt AC 87 ms 25540 KiB
03-many_bridge_yes-004.txt AC 90 ms 26724 KiB
03-many_bridge_yes-005.txt AC 89 ms 30968 KiB
03-many_bridge_yes-006.txt AC 94 ms 27268 KiB
03-many_bridge_yes-007.txt AC 88 ms 33252 KiB
03-many_bridge_yes-008.txt AC 92 ms 26384 KiB
03-many_bridge_yes-009.txt AC 85 ms 30428 KiB
03-many_bridge_yes-010.txt AC 87 ms 32984 KiB
04-small_yes-001.txt AC 3 ms 3664 KiB
04-small_yes-002.txt AC 2 ms 3528 KiB
04-small_yes-003.txt AC 2 ms 3644 KiB
04-small_yes-004.txt AC 2 ms 3628 KiB
04-small_yes-005.txt AC 2 ms 3576 KiB
05-no-001.txt AC 67 ms 30940 KiB
05-no-002.txt AC 69 ms 25384 KiB
05-no-003.txt AC 68 ms 30692 KiB
05-no-004.txt AC 63 ms 27836 KiB
05-no-005.txt AC 67 ms 21648 KiB
05-no-006.txt AC 74 ms 26608 KiB
05-no-007.txt AC 64 ms 28228 KiB
05-no-008.txt AC 66 ms 31312 KiB
05-no-009.txt AC 68 ms 24540 KiB
05-no-010.txt AC 64 ms 26408 KiB