Submission #948780

#TimeUsernameProblemLanguageResultExecution timeMemory
948780AiperiiiPipes (CEOI15_pipes)C++14
0 / 100
2723 ms29976 KiB
#include <bits/stdc++.h> //#define int long long #define ff first #define ss second #define pb push_back #define all(x) x.begin(),x.end() using namespace std; const int N=1e5+5; int p[2][N],tin[N],low[N]; vector <int> g[N]; int find_set(int i,int v){ if(p[i][v]==v)return v; return p[i][v]=find_set(i,p[i][v]); } bool union_set(int i,int u,int v){ if(find_set(i,u)==find_set(i,v))return false; p[i][u]=v; return true; } int t=0; bool ok=0; void dfs(int v,int p){ t++; tin[v]=t; low[v]=t; ok=0; for(auto to : g[v]){ if(p==to && !ok)ok=1; else if(tin[to])low[v]=min(low[v],tin[to]); else{ dfs(to,v); low[v]=min(low[v],low[to]); if(low[to]>tin[v]){ cout<<v<<" "<<to<<"\n"; } } } } signed main(){ ios_base::sync_with_stdio(); cin.tie(0);cout.tie(0); int n,m; cin>>n>>m; int i; for(i=1;i<=n;i++){ p[0][i]=i; p[1][i]=i; } int u,v; for(i=0;i<m;i++){ cin>>u>>v; if(union_set(0,u,v)){ g[u].pb(v); g[v].pb(u); } else if(union_set(1,u,v)){ g[u].pb(v); g[v].pb(u); } } for(int i=0;i<=n;i++)tin[i]=0; for(i=1;i<=n;i++){ if(!tin[i])dfs(i,0); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...