# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
125431 | 2019-07-05T09:49:00 Z | eriksuenderhauf | Pipes (CEOI15_pipes) | C++11 | 1691 ms | 12112 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] = lo[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 | 2680 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 | 140 ms | 3144 KB | Output is correct |
2 | Correct | 138 ms | 2808 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 243 ms | 3580 KB | Output is correct |
2 | Correct | 288 ms | 3292 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 406 ms | 4896 KB | Output is correct |
2 | Correct | 339 ms | 4744 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 566 ms | 9508 KB | Output is correct |
2 | Correct | 491 ms | 6736 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 879 ms | 10296 KB | Output is correct |
2 | Correct | 809 ms | 8312 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1144 ms | 12112 KB | Output is correct |
2 | Correct | 1066 ms | 8556 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1399 ms | 12108 KB | Output is correct |
2 | Correct | 1346 ms | 8568 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1691 ms | 11596 KB | Output is correct |
2 | Correct | 1605 ms | 9592 KB | Output is correct |