Submission #52625

#TimeUsernameProblemLanguageResultExecution timeMemory
52625Alexa2001Pipes (CEOI15_pipes)C++17
100 / 100
1213 ms14044 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int Nmax = 1e5 + 5; int n, m, i, x, y; int level[Nmax], low[Nmax]; vector<int> v[Nmax]; struct Forest { int t[Nmax]; void clear() { int i; for(i=1; i<=n; ++i) t[i] = i; } int boss(int x) { if(t[x] == x) return x; return t[x] = boss(t[x]); } void unite(int x, int y) { x = boss(x), y = boss(y); t[x] = y; } } A, B; void solve(int node, int dad = 0) { level[node] = low[node] = level[dad] + 1; bool ok = 0; for(auto son : v[node]) { if(son == dad && !ok) { ok = 1; continue; } if(level[son]) { low[node] = min(low[node], level[son]); continue; } solve(son, node); low[node] = min(low[node], low[son]); if(low[son] == level[son]) cout << node << ' ' << son << '\n'; } } int main() { // freopen("input", "r", stdin); // freopen("output", "w", stdout); cin.sync_with_stdio(false); cin >> n >> m; A.clear(); B.clear(); while(m--) { cin >> x >> y; if(B.boss(x) == B.boss(y)) continue; /// same bcomp if(A.boss(x) != A.boss(y)) A.unite(x, y); else B.unite(x, y); v[x].push_back(y); v[y].push_back(x); } for(i=1; i<=n; ++i) if(!level[i]) solve(i); return 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...