# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
872690 | Ghulam_Junaid | Pipes (CEOI15_pipes) | C++17 | 912 ms | 65536 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |