#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 find(int u, int dsu)
{
return (mem[max_n * dsu + u] == u ? u : mem[max_n * dsu + u] = find(mem[max_n * dsu + u], dsu));
}
bool same_set(int u, int v, int dsu)
{
return find(u, dsu) == find(v, dsu);
}
void unite(int u, int v, int dsu)
{
mem[max_n * dsu + v] = find(u, dsu);
}
int n, m, timer = 0;
vector<int> g[max_n];
int edge_xor[2 * max_n], edge_cnt = 0;
void dfs(int u, int p = -1)
{
mem[u] = mem[max_n + u] = ++timer;
for (int e : g[u])
if (e != p)
{
int v = edge_xor[e] ^ u;
if (mem[v])
mem[max_n + u] = min(mem[max_n + u], mem[v]);
else
{
dfs(v, e);
mem[max_n + u] = min(mem[max_n + u], mem[max_n + v]);
if (mem[max_n + v] > mem[u])
cout << u + 1 << ' ' << v + 1 << '\n';
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for (int i = 0; i < n; i++)
mem[i] = mem[max_n + i] = i;
for (int i = 0, a ,b; i < m; i++)
{
cin >> a >> b;
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(edge_cnt);
g[b].push_back(edge_cnt);
edge_xor[edge_cnt] = a ^ b;
edge_cnt++;
}
for (int i = 0; i < n; i++)
mem[i] = mem[max_n + i] = 0;
for (int i = 0; i < n; i++)
if (!mem[i])
dfs(i);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3412 KB |
Output is correct |
2 |
Correct |
5 ms |
3028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
3980 KB |
Output is correct |
2 |
Correct |
86 ms |
3516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
169 ms |
5964 KB |
Output is correct |
2 |
Correct |
165 ms |
4880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
65 ms |
13688 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
79 ms |
15716 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
105 ms |
16012 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
82 ms |
16860 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
97 ms |
17140 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
82 ms |
16648 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |