Submission #658134

#TimeUsernameProblemLanguageResultExecution timeMemory
658134FatihSolakPipes (CEOI15_pipes)C++17
70 / 100
1010 ms28900 KiB
#include <bits/stdc++.h> #define N 200005 using namespace std; struct DSU{ vector<int> par; void init(int n){ par.assign(n+1,0); for(int i = 1;i<=n;i++){ par[i] = i; } } int find(int a){ if(a == par[a])return a; return par[a] = find(par[a]); } bool merge(int a,int b){ a = find(a); b = find(b); if(a == b) return 0; par[a] = b; return 1; } }; int dep[N]; int mini[N]; bool vis[N]; vector<int> adj[N]; void dfs(int v,int par){ vis[v] = 1; mini[v] = dep[v]; bool ok = 0; for(auto u:adj[v]){ if(u == par && !ok){ ok = 1; continue; } if(!vis[u]){ dep[u] = dep[v] + 1; dfs(u,v); mini[v] = min(mini[v],mini[u]); } else{ mini[v] = min(mini[v],dep[u]); } } if(par != 0 && dep[v] == mini[v]){ cout << par << ' ' << v << '\n'; } } void solve(){ int n,m; cin >> n >> m; DSU d1,d2; d1.init(n); d2.init(n); for(int i = 1;i<=m;i++){ int a,b; cin >> a >> b; if(d1.merge(a,b)){ adj[a].push_back(b); adj[b].push_back(a); } else if(d2.merge(a,b)){ adj[a].push_back(b); adj[b].push_back(a); } } for(int i = 1;i<=n;i++){ if(!vis[i]) dfs(i,0); } } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef Local freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif int t=1; //cin>>t; while(t--){ solve(); } #ifdef Local cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds "; #endif }
#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...