# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
585580 | 1zaid1 | Pipes (CEOI15_pipes) | C++17 | 0 ms | 0 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;
#define endl '\n'
const int M = 1e5+1;
vector<int> node[M];
int a[M], d[M], tm = 1;
bitset<100005> vis;
vector<pair<int, int>> ans;
void dfs(int s) {
a[s] = tm++;
vis[s] = true;
for (int i:node[s]) if (!vis[i]) dfs(i);
d[s] = tm++;
}
void dfs2(int s, int p = 1) {
vis[s] = true;
for (int i:node[s]) {
if (!vis[i]) dfs2(i, s);
if (i != p) a[s] = min(a[s], a[i]);
if (i != p) d[s] = max(d[s], d[i]);
}
}
void dfs3(int s) {
vis[s] = true;
for (int i:node[s]) {
if (!vis[i]) {
if (d[i] < d[s] && a[i] > a[s]) ans.push_back({s, i});
dfs3(i);
}
}
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int a, b;
cin >> a >> b;
node[a].push_back(b);
node[b].push_back(a);
}
for (int i = 1; i <= n; i++) if (!vis[i]) dfs(i); vis = 0;
for (int i = 1; i <= n; i++) if (!vis[i]) dfs2(i); vis = 0;
for (int i = 1; i <= n; i++) if (!vis[i]) dfs3(i); vis = 0;
for (auto [a, b]:ans) cout << a << ' ' << b << endl;
return 0;
}
/*
10 11
1 7
1 8
1 6
2 8
6 7
5 8
2 5
2 3
2 4
3 4
10 9
*/