Submission #444581

#TimeUsernameProblemLanguageResultExecution timeMemory
444581prvocisloPipes (CEOI15_pipes)C++17
0 / 100
1388 ms25132 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; const int maxn = 1e5 + 5; struct dsu { int p[maxn]; int root(int r) { return r == p[r] ? r : p[r] = root(p[r]); } bool merge(int a, int b) { a = root(a), b = root(b); if (a == b) return false; p[a] = b; return true; } dsu() { for (int i = 0; i < maxn; i++) p[i] = i; } } d[2]; int vis[maxn], tin[maxn], low[maxn], n, m, timer = 0; vector<int> g[maxn]; void bridge(int a, int b) { cout << a+1 << " " << b+1 << "\n"; } void dfs(int u, int p) { low[u] = tin[u] = timer++, vis[u] = true; for (int v : g[u]) { if (v != p && vis[v]) low[u] = min(low[u], tin[v]); else if (v != p) { dfs(v, u); low[u] = min(low[u], low[v]); } } if (p != -1 && tin[p] < low[u]) bridge(u, p); } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (int i = 0, a, b; i < m; i++) { cin >> a >> b; a--, b--; if (d[0].merge(a, b) || d[1].merge(a, b)) { //cout << "edge " << a << " " << b << endl; g[a].push_back(b), g[b].push_back(a); } } //cout << "bridges:\n"; for (int i = 0; i < n; i++) if (!vis[i]) dfs(i, -1); 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...