#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 = 30001;
int n, m, ti[max_n] = {0}, lo[max_n], timer = 0;
vector<int> g[max_n];
int par[2][max_n];
int find(int u, int dsu)
{
while (par[dsu][u] != u)
par[dsu][u] = par[dsu][par[dsu][u]], u = par[dsu][u];
return u;
}
bool same_set(int u, int v, int dsu)
{
return find(u, dsu) == find(v, dsu);
}
void unite(int u, int v, int dsu)
{
par[dsu][find(v, dsu)] = find(u, dsu);
}
void dfs(int u, int p = -1)
{
ti[u] = lo[u] = ++timer;
for (int v : g[u])
if (v != p)
{
if (ti[v])
lo[u] = min(lo[u], ti[v]);
else
{
dfs(v, u);
lo[u] = min(lo[u], lo[v]);
if (lo[v] > ti[u] && !(same_set(u, v, 0) && same_set(u, v, 1)))
cout << u << ' ' << v << '\n';
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for (int i = 1; i <= n; i++)
par[0][i] = par[1][i] = i;
for (int i = 0, a ,b; i < m; i++)
{
cin >> a >> b;
if (!same_set(a, b, 0))
unite(a, b, 0);
else if (!same_set(a, b, 1))
unite(a, b, 1);
else continue;
g[a].push_back(b);
g[b].push_back(a);
}
for (int i = 1; i <= n; i++)
if (!ti[i])
dfs(i);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1492 KB |
Output is correct |
2 |
Correct |
4 ms |
1236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
1452 KB |
Output is correct |
2 |
Correct |
78 ms |
1228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
146 ms |
2128 KB |
Output is correct |
2 |
Correct |
159 ms |
1616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
230 ms |
3828 KB |
Output is correct |
2 |
Correct |
200 ms |
3392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
2312 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
2368 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
2268 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
2260 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
2260 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |