This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n = 100000;
int mem[2 * max_n];
int *e[2];
int find(const int &u, const int &dsu)
{
return (e[dsu][u] < 0 ? u : e[dsu][u] = find(e[dsu][u], dsu));
}
bool same_set(const int &u, const int &v, const int &dsu)
{
return find(u, dsu) == find(v, dsu);
}
bool unite(int u, int v, const int &dsu)
{
u = find(u, dsu), v = find(v, dsu);
if (u == v) return false;
if (e[dsu][u] > e[dsu][v]) swap(u, v);
e[dsu][u] += e[dsu][v], e[dsu][v] = u;
}
int n, m, timer = 0;
vector<int> g[max_n];
int edge_xor[2 * max_n], edge_cnt = 0;
int *ti, *lo;
void dfs(const int &u, const int &p)
{
ti[u] = lo[u] = ++timer;
for (const int &e : g[u])
if (e != p)
{
int v = edge_xor[e] ^ u;
if (ti[v])
lo[u] = min(lo[u], ti[v]);
else
{
dfs(v, e);
lo[u] = min(lo[u], lo[v]);
if (lo[v] > ti[u])
cout << u + 1 << ' ' << v + 1 << '\n';
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
e[0] = &mem[0];
e[1] = &mem[max_n];
for (int i = 0; i < n; i++)
e[0][i] = e[1][i] = -1;
for (int i = 0, a ,b; i < m; i++)
{
cin >> a >> b;
a--, b--;
if (!unite(a, b, 0) && !unite(a, b, 1))
continue;
g[a].push_back(edge_cnt);
g[b].push_back(edge_cnt);
edge_xor[edge_cnt] = a ^ b;
edge_cnt++;
}
ti = &mem[0];
lo = &mem[max_n];
for (int i = 0; i < n; i++)
ti[i] = lo[i] = 0;
for (int i = 0; i < n; i++)
if (!ti[i])
dfs(i, -1);
return 0;
}
Compilation message (stderr)
pipes.cpp: In function 'bool unite(int, int, const int&)':
pipes.cpp:27:39: warning: control reaches end of non-void function [-Wreturn-type]
27 | e[dsu][u] += e[dsu][v], e[dsu][v] = u;
| ~~~~~~~~~~^~~
# | 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... |