# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
804597 | Hanksburger | Pipes (CEOI15_pipes) | C++17 | 797 ms | 23268 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;
vector<int> adj[100005];
int par[100005][2], t;
int findPar(int u, int x)
{
return (par[u][x]==u?u:par[u][x]=findPar(par[u][x], x));
}
void dfs(int u, int p)
{
par[u][0]=par[u][1]=(++t);
int pass=1;
for (int v:adj[u])
{
if (v==p && pass)
{
pass=0;
continue;
}
if (par[v][0])
par[u][1]=min(par[u][1], par[v][0]);
else
{
dfs(v, u);
par[u][1]=min(par[u][1], par[v][1]);
if (par[v][1]>=par[v][0])
cout << u << ' ' << v << '\n';
}
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
for (int i=1; i<=n; i++)
par[i][0]=par[i][1]=i;
for (int i=1; i<=m; i++)
{
int u, v, U, V;
cin >> u >> v;
if (findPar(u, 0)!=findPar(v, 0))
{
par[par[u][0]][0]=par[v][0];
adj[u].push_back(v);
adj[v].push_back(u);
}
else if (findPar(u, 1)!=findPar(v, 1))
{
par[par[u][1]][1]=par[v][1];
adj[u].push_back(v);
adj[v].push_back(u);
}
}
for (int i=1; i<=n; i++)
par[i][0]=par[i][1]=0;
for (int i=1; i<=n; i++)
if (!par[i][0])
dfs(i, 0);
}
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... |