제출 #1080165

#제출 시각아이디문제언어결과실행 시간메모리
1080165jk_Pipes (CEOI15_pipes)C++17
50 / 100
774 ms51336 KiB
#include <bits/stdc++.h> using namespace std; const int N = 100000; struct ufind { array<int, N>& c; ufind(array<int, N>& c) : c(c) { iota(c.begin(), c.end(), 0); } int find(int k) { return c[k] == k ? k : (c[k] = find(c[k])); } void unite(int a, int b) { c[find(a)] = find(b); } }; struct edge { int to; int next; }; array<edge, 4*N> edges; int edges_i = 0; array<int, N> g; int timer=0; array<int, N> pre; array<int, N> low; void dfs(int v, int p = -1) { pre[v] = low[v] = timer++; bool used_p = false; for (int e = g[v]; e != -1; e = edges[e].next) { int w = edges[e].to; if (w == p && !used_p) { used_p = true; continue; } if (pre[w] != -1) { low[v] = min(low[v], pre[w]); } else { dfs(w, v); low[v] = min(low[v], low[w]); if (low[w] > pre[v]) { cout << v+1 << ' ' << w+1 << '\n'; } } } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); fill(g.begin(), g.end(), -1); int n, m; cin >> n >> m; assert(n <= N); { array<ufind, 2> msts{{ufind(pre), ufind(low)}}; for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; --a; --b; for (auto& mst : msts) { if (mst.find(a) != mst.find(b)) { mst.unite(a, b); edges[edges_i] = {b, g[a]}; g[a] = edges_i++; edges[edges_i] = {a, g[b]}; g[b] = edges_i++; break; } } } } fill(pre.begin(), pre.end(), -1); fill(low.begin(), low.end(), -1); for (int i = 0; i < n; ++i) if (pre[i] == -1) dfs(i); }
#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...