# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
460891 | 2021-08-09T10:44:37 Z | kingfran1907 | Pipes (CEOI15_pipes) | C++14 | 1500 ms | 23436 KB |
#include <bits/stdc++.h> #define X first #define Y second using namespace std; typedef long long llint; const int maxn = 1e5+10; const int base = 31337; const int mod = 1e9+7; const int inf = 0x3f3f3f3f; const int logo = 18; const int off = 1 << logo; const int treesiz = off << 1; struct union_find { int parr[maxn]; union_find() { for (int i = 0; i < maxn; i++) parr[i] = i; } int fin(int x) { if (x == parr[x]) return x; return parr[x] = fin(parr[x]); } void merg(int a, int b) { a = fin(a); b = fin(b); if (a == b) return; int ra = rand() % 2; if (ra == 0) parr[b] = a; else parr[a] = b; } }; int n, m; vector< int > graph[maxn]; union_find p, q; int dep[maxn]; int dfs(int x, int parr) { int out = 0; dep[x] = 1 + dep[parr]; for (int tren : graph[x]) { if (tren == parr) continue; if (dep[tren] == -1) { int kol = dfs(tren, x); if (kol == 0) { printf("%d %d\n", tren, x); } out = max(out, kol - 1); } else { int dis = dep[x] - dep[tren]; out = max(out, dis); } } return out; } int main() { srand(time(0)); scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { int a, b; scanf("%d%d", &a, &b); if (q.fin(a) != q.fin(b)) { graph[a].push_back(b); graph[b].push_back(a); if (p.fin(a) != p.fin(b)) p.merg(a, b); else q.merg(a, b); } } memset(dep, -1, sizeof dep); dep[0] = 0; for (int i = 1; i <= n; i++) { if (dep[i] == -1) dfs(i, 0); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 3804 KB | Output is correct |
2 | Incorrect | 3 ms | 3788 KB | Wrong number of edges |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 4300 KB | Output is correct |
2 | Incorrect | 7 ms | 3916 KB | Wrong number of edges |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 127 ms | 4204 KB | Output is correct |
2 | Incorrect | 128 ms | 4072 KB | Wrong number of edges |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 237 ms | 4840 KB | Wrong number of edges |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 356 ms | 19140 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 541 ms | 23392 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 777 ms | 21880 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1016 ms | 19808 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1235 ms | 20084 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1500 ms | 23436 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |