Submission #673846

#TimeUsernameProblemLanguageResultExecution timeMemory
673846benjaminkleynPipes (CEOI15_pipes)C++17
80 / 100
1033 ms53100 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2") #include <bits/stdc++.h> using namespace std; typedef long long ll; const int max_n = 100000; int mem[2 * max_n]; int *e[2]; int find(const int &u, const int &dsu) { return (e[dsu][u] < 0 ? u : e[dsu][u] = find(e[dsu][u], dsu)); } int n, m, timer = 0; vector<int> g[max_n]; int edge_xor[2 * max_n], edge_cnt = 0; int *ti, *lo; void dfs(const int &u, const int &p) { ti[u] = lo[u] = ++timer; for (const int &e : g[u]) if (e != p) { int v = edge_xor[e] ^ u; if (ti[v]) lo[u] = min(lo[u], ti[v]); else { dfs(v, e); lo[u] = min(lo[u], lo[v]); if (lo[v] > ti[u]) cout << u + 1 << ' ' << v + 1 << '\n'; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; e[0] = &mem[0]; e[1] = &mem[max_n]; for (int i = 0; i < n; i++) e[0][i] = e[1][i] = -1; for (int i = 0, a, b, A, B; i < m; i++) { cin >> a >> b; a--, b--; if ((A = find(a, 0)) != (B = find(b, 0))) { if (e[0][A] > e[0][B]) swap(A, B); e[0][A] += e[0][B], e[0][B] = A; } else if ((A = find(a, 1)) != (B = find(b, 1))) { if (e[1][A] > e[1][B]) swap(A, B); e[1][A] += e[1][B], e[1][B] = A; } else continue; g[a].push_back(edge_cnt); g[b].push_back(edge_cnt); edge_xor[edge_cnt] = a ^ b; edge_cnt++; } ti = &mem[0]; lo = &mem[max_n]; for (int i = 0; i < n; i++) ti[i] = lo[i] = 0; for (int i = 0; i < n; i++) if (!ti[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...