#include <bits/stdc++.h>
using namespace std;
const int N = 70'010;
struct dsu {
int e[N];
int find(int x) { return e[x] < 0 ? x : e[x] = find(e[x]); }
bool join(int a, int b) {
a = find(a), b = find(b);
if (a == b) return false;
if (e[a] > e[b]) swap(a, b);
e[a] += e[b]; e[b] = a;
return true;
}
} d1, d2;
vector<int> g[N];
int timer=0;
void dfs(int &at, int &par) {
bool ck=0;
d1.e[at]=d2.e[at]=++timer;
for(int &to:g[at]) {
if(to == par and ck==0) {
ck=1;
continue;
}
if(d2.e[to]) {
d1.e[at]=min(d1.e[at], d2.e[to]);
} else {
dfs(to, at);
d1.e[at]=min(d1.e[at], d1.e[to]);
}
}
if(d1.e[at] == d2.e[at] and at!=par) {
cout << at << " " << par << "\n";
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
srand(time(0)):
int n, m;
cin >> n >> m;
int u, v;
for(int i = 1;i<N;i++)d1.e[i]=d2.e[i]=-1;
for(int i = 0;i<m;i++) {
cin >> u >> v;
if(rnd()%2==0 and d1.join(u, v) || d2.join(u, v)) {
g[u].push_back(v);
g[v].push_back(u);
}
else if(d2.join(u, v) || d1.join(u, v)) {
g[u].push_back(v);
g[v].push_back(u);
}
}
for(int i = 1;i<=N;i++)d1.e[i]=d2.e[i]=0;
for(int i= 1;i<=n;i++) {
if(!d1.e[i]) {
dfs(i, i);
}
}
}
Compilation message
pipes.cpp: In function 'int main()':
pipes.cpp:40:16: error: expected ';' before ':' token
40 | srand(time(0)):
| ^
| ;
pipes.cpp:42:9: error: 'n' was not declared in this scope
42 | cin >> n >> m;
| ^
pipes.cpp:42:14: error: 'm' was not declared in this scope
42 | cin >> n >> m;
| ^
pipes.cpp:47:6: error: 'rnd' was not declared in this scope; did you mean 'rand'?
47 | if(rnd()%2==0 and d1.join(u, v) || d2.join(u, v)) {
| ^~~
| rand