# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
872690 | 2023-11-13T15:02:56 Z | Ghulam_Junaid | Pipes (CEOI15_pipes) | C++17 | 912 ms | 65536 KB |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int par1[N], par2[N], h[N], mnh[N]; bool vis[N]; vector<int> g[N]; vector<pair<int, int>> bridges; int root1(int v){ return (par1[v] == -1 ? v : par1[v] = root1(par1[v])); } int root2(int v){ return (par2[v] == -1 ? v : par2[v] = root2(par2[v])); } void merge1(int u, int v){ int r1 = root1(v); int r2 = root1(u); par1[r1] = r2; g[v].push_back(u); g[u].push_back(v); } void merge2(int u, int v){ int r1 = root2(u); int r2 = root2(v); if (r1 == r2) return; par2[r1] = r2; g[v].push_back(u); g[u].push_back(v); } void dfs(int v, int p = -1){ vis[v] = 1; mnh[v] = h[v]; for (int u : g[v]){ if (vis[u]){ if (u != p) mnh[v] = min(mnh[v], h[u]); continue; } h[u] = h[v] + 1; dfs(u, v); mnh[v] = min(mnh[v], mnh[u]); if (mnh[u] >= h[u]) bridges.push_back({u, v}); } } int main(){ int n, m; scanf("%d%d", &n, &m); for (int i=1; i<=n; i++) par1[i] = par2[i] = -1; for (int i=0; i<m; i++){ int u, v; scanf("%d%d", &u, &v); if (root1(u) == root1(v)) merge2(u, v); else merge1(u, v); } for (int v = 1; v <= n; v++) if (!vis[v]) dfs(v); for (auto [u, v] : bridges) printf("%d %d\n", u, v); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2652 KB | Output is correct |
2 | Incorrect | 1 ms | 2652 KB | Wrong number of edges |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 3420 KB | Output is correct |
2 | Incorrect | 4 ms | 3164 KB | Wrong number of edges |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 84 ms | 8448 KB | Output is correct |
2 | Incorrect | 82 ms | 8188 KB | Wrong number of edges |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 139 ms | 13396 KB | Wrong number of edges |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 230 ms | 21588 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 308 ms | 31984 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 456 ms | 45084 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 608 ms | 57940 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 743 ms | 65536 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 912 ms | 65536 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |