# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
46453 | 2018-04-20T22:08:39 Z | alex99 | Pipes (CEOI15_pipes) | C++14 | 1519 ms | 7948 KB |
#include <iostream> #include <vector> #include <cstdlib> #include <cstdio> #include <ctime> using namespace std; int N, M; int TT[100005], R[100005]; long long Sum[100005]; int F[100005]; vector <int> G[100005]; bool Use[100005]; void Unite(int x, int y) { if(x == y) return; if(R[x] < R[y]) { TT[x] = y; } else TT[y] = x; if(R[x] == R[y]) R[x]++; } int Father(int x) { int init = x; while(x != TT[x]) x = TT[x]; while(init != x) { int next = TT[init]; TT[init] = x; init = next; } return x; } void DFS(int node) { Use[node] = 1; for(int i = 0; i < G[node].size(); i++) { int neighb = G[node][i]; if(neighb == F[node]) continue; F[neighb] = node; DFS(neighb); Sum[node] += Sum[neighb]; } if(Sum[node] == 0 && F[node] != 0) { printf("%d %d\n", node, F[node]); } } void Solve() { scanf("%d%d", &N, &M); for(int i = 1; i <= N; i++) TT[i] = i; for(int i = 1; i <= M; i++) { int x, y; scanf("%d%d", &x, &y); if(Father(x) == Father(y)) { int r = rand(); Sum[x] += r; Sum[y] -= r; } else { G[x].push_back(y); G[y].push_back(x); Unite(Father(x), Father(y)); } } for(int i = 1; i <= N; i++) if(Use[i] == 0) DFS(i); } int main() { srand(time(NULL)); Solve(); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2688 KB | Output is correct |
2 | Correct | 4 ms | 2748 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 2952 KB | Output is correct |
2 | Correct | 7 ms | 2880 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 117 ms | 2900 KB | Output is correct |
2 | Correct | 115 ms | 2908 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 201 ms | 3180 KB | Output is correct |
2 | Correct | 236 ms | 3172 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 347 ms | 3844 KB | Output is correct |
2 | Correct | 294 ms | 4216 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 480 ms | 6288 KB | Output is correct |
2 | Correct | 392 ms | 6264 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 721 ms | 6912 KB | Output is correct |
2 | Correct | 709 ms | 6916 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1063 ms | 7780 KB | Output is correct |
2 | Correct | 917 ms | 7800 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1318 ms | 7780 KB | Output is correct |
2 | Correct | 1390 ms | 7812 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1519 ms | 7544 KB | Output is correct |
2 | Correct | 1469 ms | 7948 KB | Output is correct |