Submission #444589

#TimeUsernameProblemLanguageResultExecution timeMemory
444589prvocisloPipes (CEOI15_pipes)C++17
90 / 100
1371 ms19288 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; bool seen = false; for (int v : g[u]) { if (v == p && !seen) seen = true; else if (vis[v]) low[u] = min(low[u], tin[v]); else { dfs(v, u); low[u] = min(low[u], low[v]); } } if (p != -1 && tin[u] == low[u]) bridge(u, p); } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; int cnt = 0; 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)) {cnt++; //cout << "edge " << a << " " << b << endl; g[a].push_back(b), g[b].push_back(a); } } //cout << cnt << "\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...