# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
41869 | 2018-02-21T18:36:03 Z | octopuses | Pipes (CEOI15_pipes) | C++14 | 2716 ms | 8308 KB |
//Giorgi Kldiashvili #include <bits/stdc++.h> #define ll long long #define M 1000000007ll using namespace std; const int N = 100001; int n, m, x, y, timer; int p[N], P[N], c[N], d[N], in[N], out[N]; vector < int > G[N]; bool used[N]; int Parent(int x) { if(P[x] == x) return x; return P[x] = Parent(P[x]); } void go(int v) { c[v] = d[v] = in[v] = ++ timer; used[v] = true; for(int i = 0; i < G[v].size(); ++ i) { if(used[G[v][i]]) continue; p[G[v][i]] = v; go(G[v][i]); } out[v] = timer; } void dfs(int v) { used[v] = true; for(int i = 0; i < G[v].size(); ++ i) { if(used[G[v][i]]) continue; dfs(G[v][i]); c[v] = min(c[v], c[G[v][i]]); d[v] = max(d[v], d[G[v][i]]); } if(p[v] == 0) return; if(c[v] >= in[v] && d[v] <= out[v]) printf("%d %d\n", v, p[v]); } int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); scanf("%d %d", &n, &m); for(int i = 1; i <= n; ++ i) P[i] = i; while(m --) { scanf("%d %d", &x, &y); if(Parent(x) == Parent(y)) continue; P[Parent(x)] = y; G[x].push_back(y); G[y].push_back(x); } for(int i = 1; i <= n; ++ i) { if(used[i]) continue; go(i); } rewind(stdin); scanf("%d %d", &n, &m); for(int i = 1; i <= n; ++ i) P[i] = i, used[i] = 0; while(m --) { scanf("%d %d", &x, &y); if(Parent(x) == Parent(y)) { c[x] = min(c[x], in[y]); d[x] = max(d[x], in[y]); d[y] = max(d[y], in[x]); c[y] = min(c[y], in[x]); continue; } P[Parent(x)] = y; } for(int i = 1; i <= n; ++ i) { if(used[i]) continue; dfs(i); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 2688 KB | Output is correct |
2 | Correct | 3 ms | 2688 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 2944 KB | Output is correct |
2 | Correct | 10 ms | 2944 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 223 ms | 2852 KB | Output is correct |
2 | Correct | 218 ms | 2924 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 402 ms | 3200 KB | Output is correct |
2 | Correct | 458 ms | 3312 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 642 ms | 3944 KB | Output is correct |
2 | Correct | 559 ms | 4344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 843 ms | 6608 KB | Output is correct |
2 | Correct | 738 ms | 6732 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1409 ms | 7112 KB | Output is correct |
2 | Correct | 1345 ms | 7236 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1806 ms | 8160 KB | Output is correct |
2 | Correct | 1699 ms | 8300 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2395 ms | 8164 KB | Output is correct |
2 | Correct | 2169 ms | 8300 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2716 ms | 7976 KB | Output is correct |
2 | Correct | 2622 ms | 8308 KB | Output is correct |