# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
146323 | 2019-08-23T13:11:43 Z | evpipis | Pipes (CEOI15_pipes) | C++ | 1908 ms | 15972 KB |
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair typedef pair<int, int> ii; const int len = 1e5+3; int n, m, cnt; int par[len], num[len], low[len]; vector<ii> adj[len], vec; struct dsu{ int anc[len]; void init(){ for (int i = 1; i <= n; i++) anc[i] = i; } int fin(int i){ if (anc[i] == i) return i; return anc[i] = fin(anc[i]); } void join(int i, int j){ i = fin(i), j = fin(j); if (i != j) anc[j] = i; } }; dsu one, two; void dfs(int u){ num[u] = low[u] = ++cnt; for (int j = 0; j < adj[u].size(); j++){ ii v = adj[u][j]; if (!num[v.fi]){ par[v.fi] = v.se; dfs(v.fi); if (low[v.fi] > num[u]) printf("%d %d\n", u, v.fi); low[u] = min(low[u], low[v.fi]); } else if (v.se != par[u]){ low[u] = min(low[u], num[v.fi]); } } } int main(){ scanf("%d %d", &n, &m); one.init(); two.init(); for (int i = 0; i < m; i++){ int a, b; scanf("%d %d", &a, &b); if (one.fin(a) != one.fin(b)){ vec.pb(mp(a, b)); one.join(a, b); } else if (two.fin(a) != two.fin(b)){ vec.pb(mp(a, b)); two.join(a, b); } } for (int i = 0; i < vec.size(); i++){ int a = vec[i].fi, b = vec[i].se; adj[a].pb(mp(b, i+1)); adj[b].pb(mp(a, i+1)); } for (int i = 1; i <= n; i++) if (!num[i]) dfs(i); 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 | 3320 KB | Output is correct |
2 | Correct | 9 ms | 3064 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 143 ms | 3136 KB | Output is correct |
2 | Correct | 140 ms | 3064 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 249 ms | 3984 KB | Output is correct |
2 | Correct | 288 ms | 4980 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 420 ms | 5840 KB | Output is correct |
2 | Correct | 377 ms | 5484 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 605 ms | 12144 KB | Output is correct |
2 | Correct | 516 ms | 9828 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 916 ms | 13436 KB | Output is correct |
2 | Correct | 929 ms | 10284 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1274 ms | 15972 KB | Output is correct |
2 | Correct | 1139 ms | 12776 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1508 ms | 15972 KB | Output is correct |
2 | Correct | 1436 ms | 12900 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1813 ms | 15400 KB | Output is correct |
2 | Correct | 1908 ms | 12332 KB | Output is correct |