Skip to content

Commit 33fcb6d

Browse files
committed
add bridge test
1 parent 9fe30d2 commit 33fcb6d

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

tests/library_checker_aizu_tests/graphs/bcc_callback.test.cpp renamed to tests/library_checker_aizu_tests/graphs/bcc_callback_lib_checker_bcc.test.cpp

File renamed without changes.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#define PROBLEM \
2+
"https://judge.yosupo.jp/problem/two_edge_connected_components"
3+
#include "../template.hpp"
4+
#include "../../../library/graphs/bridges_cuts/bcc_callback.hpp"
5+
#include "../../../kactl/content/data-structures/UnionFind.h"
6+
int main() {
7+
cin.tie(0)->sync_with_stdio(0);
8+
int n, m;
9+
cin >> n >> m;
10+
vector<basic_string<int>> adj(n), adj_e_id(n);
11+
for (int i = 0; i < n; i++) adj[i] += i;
12+
for (int i = 0; i < m; i++) {
13+
int u, v;
14+
cin >> u >> v;
15+
adj[u] += v;
16+
adj[v] += u;
17+
adj_e_id[u] += i;
18+
adj_e_id[v] += i;
19+
}
20+
21+
UF uf(n);
22+
vector<bool> seen(m);
23+
bcc_callback(adj, [&](const vi& nodes) {
24+
int cnt_edges = 0;
25+
rep(i,0,sz(nodes)-1)
26+
for(int e_id : adj_e_id[nodes[i]])
27+
if(!seen[e_id]) {
28+
seen[e_id] = 1;
29+
cnt_edges++;
30+
}
31+
if (cnt_edges >= 2)
32+
for (int v : nodes) uf.join(v, nodes[0]);
33+
});
34+
35+
vector<basic_string<int>> two_edge_ccs(n);
36+
rep(i,0,n) two_edge_ccs[uf.find(i)] += i;
37+
int cnt_ccs = 0;
38+
rep(i,0,n) cnt_ccs += (!empty(two_edge_ccs[i]));
39+
cout<<cnt_ccs<<'\n';
40+
rep(i,0,n) {
41+
if(!empty(two_edge_ccs[i])) {
42+
cout<<sz(two_edge_ccs[i])<<' ';
43+
for(int v:two_edge_ccs[i]) cout<<v<<' ';
44+
cout<<'\n';
45+
}
46+
}
47+
48+
return 0;
49+
}

0 commit comments

Comments
 (0)