#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 *e[2];
int find(const int &u, const int &dsu)
{
return (e[dsu][u] < 0 ? u : e[dsu][u] = find(e[dsu][u], dsu));
}
bool same_set(const int &u, const int &v, const int &dsu)
{
return find(u, dsu) == find(v, dsu);
}
void unite(int u, int v, const int &dsu)
{
u = find(u, dsu), v = find(v, dsu);
if (u == v) return;
if (e[dsu][u] > e[dsu][v]) swap(u, v);
e[dsu][u] += e[dsu][v], e[dsu][v] = u;
}
int n, m, timer = 0;
vector<int> g[max_n];
int edge_xor[2 * max_n], edge_cnt = 0;
int *ti, *lo;
void dfs(const int &u, const int &p)
{
ti[u] = lo[u] = ++timer;
for (const int &e : g[u])
if (e != p)
{
int v = edge_xor[e] ^ u;
if (ti[v])
lo[u] = min(lo[u], ti[v]);
else
{
dfs(v, e);
lo[u] = min(lo[u], lo[v]);
if (lo[v] > ti[u])
cout << u + 1 << ' ' << v + 1 << '\n';
}
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
e[0] = &mem[0];
e[1] = &mem[max_n];
for (int i = 0; i < n; i++)
e[0][i] = e[1][i] = -1;
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++;
}
ti = &mem[0];
lo = &mem[max_n];
for (int i = 0; i < n; i++)
ti[i] = lo[i] = 0;
for (int i = 0; i < n; i++)
if (!ti[i])
dfs(i, -1);
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 |
3208 KB |
Output is correct |
2 |
Correct |
6 ms |
2948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
5220 KB |
Output is correct |
2 |
Correct |
88 ms |
5040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
143 ms |
5824 KB |
Output is correct |
2 |
Correct |
183 ms |
5372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
247 ms |
7524 KB |
Output is correct |
2 |
Runtime error |
207 ms |
18692 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
328 ms |
10756 KB |
Output is correct |
2 |
Runtime error |
282 ms |
25324 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
513 ms |
11912 KB |
Output is correct |
2 |
Runtime error |
536 ms |
24184 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
699 ms |
14148 KB |
Output is correct |
2 |
Runtime error |
721 ms |
28004 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
830 ms |
17904 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1002 ms |
30216 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |