#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 *par[2];
int find(int u, int dsu)
{
return (par[dsu][u] == u ? u : par[dsu][u] = find(par[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)
{
par[dsu][find(v, dsu)] = find(u, dsu);
}
int n, m, timer = 0;
vector<int> g[max_n];
int edge_xor[2 * max_n], edge_cnt = 0;
int *ti, *lo;
void dfs(int u, int p = -1)
{
ti[u] = lo[u] = ++timer;
for (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;
par[0] = &mem[0];
par[1] = &mem[max_n];
for (int i = 0; i < n; i++)
par[0][i] = par[1][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++;
}
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);
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 |
3156 KB |
Output is correct |
2 |
Correct |
5 ms |
2900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
2996 KB |
Output is correct |
2 |
Correct |
84 ms |
2856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
153 ms |
3716 KB |
Output is correct |
2 |
Correct |
174 ms |
3204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
231 ms |
5276 KB |
Output is correct |
2 |
Correct |
220 ms |
5040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
371 ms |
10700 KB |
Output is correct |
2 |
Correct |
286 ms |
7140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
543 ms |
11816 KB |
Output is correct |
2 |
Correct |
524 ms |
8852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
689 ms |
14092 KB |
Output is correct |
2 |
Correct |
641 ms |
9308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
850 ms |
14440 KB |
Output is correct |
2 |
Runtime error |
827 ms |
61856 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1010 ms |
13908 KB |
Output is correct |
2 |
Runtime error |
1153 ms |
65536 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |