# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
125430 | 2019-07-05T09:48:29 Z | eriksuenderhauf | Pipes (CEOI15_pipes) | C++11 | 1724 ms | 12156 KB |
//#pragma GCC optimize("O3") #include <bits/stdc++.h> #define pb push_back using namespace std; const int MAXN = 1e5 + 5; vector<int> adj[MAXN]; int cnt = 1, par[MAXN], par2[MAXN], lo[MAXN]; int qry(int x) { return x == par[x] ? x : par[x] = qry(par[x]); } void join(int u, int v) { u = qry(u), v = qry(v); par[u] = v; } int qry2(int x) { return x == par2[x] ? x : par2[x] = qry2(par2[x]); } void join2(int u, int v) { u = qry2(u), v = qry2(v); par2[u] = v; } void dfs(int u, int p) { par[u] = lo[u] = cnt++; while (!adj[u].empty()) { int v = adj[u].back(); adj[u].pop_back(); if (!par[v]) { dfs(v, u); lo[u] = min(lo[u], lo[v]); if (lo[v] > par[u] && qry2(u) != qry2(v)) printf("%d %d\n", u, v); } else if (v != p) lo[u] = min(lo[u], par[v]); } } int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) par[i] = par2[i] = i; for (int i = 0; i < m; i++) { int u, v; scanf("%d %d", &u, &v); if (qry2(u) == qry2(v)) continue; if (qry(u) == qry(v)) { adj[u].pb(v); adj[v].pb(u); join2(u, v); continue; } join(u, v); adj[u].pb(v); adj[v].pb(u); } for (int i = 1; i <= n; i++) par[i] = 0; for (int i = 1; i <= n; i++) if (!par[i]) dfs(i, 0); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2684 KB | Output is correct |
2 | Correct | 4 ms | 2680 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 3064 KB | Output is correct |
2 | Correct | 9 ms | 2936 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 144 ms | 3020 KB | Output is correct |
2 | Correct | 141 ms | 2936 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 251 ms | 3676 KB | Output is correct |
2 | Correct | 291 ms | 3192 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 408 ms | 4888 KB | Output is correct |
2 | Correct | 356 ms | 4760 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 573 ms | 9400 KB | Output is correct |
2 | Correct | 505 ms | 6852 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 914 ms | 10296 KB | Output is correct |
2 | Correct | 837 ms | 8284 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1162 ms | 12156 KB | Output is correct |
2 | Correct | 1107 ms | 8568 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1457 ms | 12152 KB | Output is correct |
2 | Correct | 1360 ms | 8440 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1724 ms | 11640 KB | Output is correct |
2 | Correct | 1638 ms | 9372 KB | Output is correct |