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>
typedef long long ll;
using namespace std;
const int maxn = 1e5 + 5;
struct dsu
{
int p[maxn];
int root(int r) { return r == p[r] ? r : p[r] = root(p[r]); }
bool merge(int a, int b)
{
a = root(a), b = root(b);
if (a == b) return false;
p[a] = b;
return true;
}
dsu() { for (int i = 0; i < maxn; i++) p[i] = i; }
} d[2];
int vis[maxn], tin[maxn], low[maxn], n, m, timer = 0;
vector<int> g[maxn];
void bridge(int a, int b) { cout << a+1 << " " << b+1 << "\n"; }
void dfs(int u, int p)
{
low[u] = tin[u] = timer++, vis[u] = true;
bool seen = false;
for (int v : g[u])
{
if (v == p && !seen) seen = true;
else if (vis[v]) low[u] = min(low[u], tin[v]);
else
{
dfs(v, u);
low[u] = min(low[u], low[v]);
}
}
if (p != -1 && tin[u] == low[u])
bridge(u, p);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
int cnt = 0;
for (int i = 0, a, b; i < m; i++)
{
cin >> a >> b; a--, b--;
if (d[0].merge(a, b) || d[1].merge(a, b))
{cnt++;
//cout << "edge " << a << " " << b << endl;
g[a].push_back(b), g[b].push_back(a);
}
}
//cout << cnt << "\n";
for (int i = 0; i < n; i++) if (!vis[i]) dfs(i, -1);
return 0;
}
# | 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... |