# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
44883 | 2018-04-08T21:28:45 Z | bogdan10bos | Pipes (CEOI15_pipes) | C++14 | 1370 ms | 13396 KB |
#include <bits/stdc++.h> using namespace std; //#define FILE_IO typedef pair<int, int> pii; int N, M; int h[100005], low[100005], vis[100005]; vector<int> edg[100005]; class UnionFind { public: int N; int f[100005]; void init(int _N) { N = _N; for(int i = 1; i <= N; i++) f[i] = i; } int F(int x) { if(f[x] == x) return x; return f[x] = F(f[x]); } void unite(int x, int y) { if(F(x) == F(y)) return; f[F(y)] = F(x); } }; UnionFind f[2]; void DFS(int nod, int fth) { h[nod] = h[fth] + 1; low[nod] = h[nod]; vis[nod] = 1; int father = 0; for(auto nxt: edg[nod]) { if(nxt == fth) { father++; if(father == 1) continue; } if(vis[nxt]) { low[nod] = min(low[nod], low[nxt]); continue; } DFS(nxt, nod); low[nod] = min(low[nod], low[nxt]); if(low[nxt] > h[nod]) printf("%d %d\n", nod, nxt); } } int main() { #ifdef FILE_IO freopen("1.in", "r", stdin); freopen("1.out", "w", stdout); #endif scanf("%d%d", &N, &M); f[0].init(N), f[1].init(N); int cnt = 0; for(int i = 1; i <= M; i++) { int x, y; scanf("%d%d", &x, &y); if(f[1].F(x) == f[1].F(y)) continue; edg[x].push_back(y); edg[y].push_back(x); if(f[0].F(x) != f[0].F(y)) f[0].unite(x, y); else f[1].unite(x, y); } for(int i = 1; i <= N; i++) if(!vis[i]) DFS(i, 0); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2688 KB | Output is correct |
2 | Correct | 4 ms | 2688 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 3200 KB | Output is correct |
2 | Correct | 8 ms | 3028 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 114 ms | 3036 KB | Output is correct |
2 | Correct | 120 ms | 2884 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 193 ms | 3700 KB | Output is correct |
2 | Correct | 224 ms | 3304 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 312 ms | 5268 KB | Output is correct |
2 | Correct | 269 ms | 4948 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 473 ms | 10208 KB | Output is correct |
2 | Correct | 415 ms | 7368 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 706 ms | 11308 KB | Output is correct |
2 | Correct | 664 ms | 8804 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 979 ms | 13384 KB | Output is correct |
2 | Correct | 882 ms | 9300 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1143 ms | 13396 KB | Output is correct |
2 | Correct | 1089 ms | 9428 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1370 ms | 12880 KB | Output is correct |
2 | Correct | 1324 ms | 10472 KB | Output is correct |