Skip to content

Commit 67e41c6

Browse files
lrvideckisweb-flow
andauthored
Add more bcc callback tests (#139)
* add bridge test * format test now * [auto-verifier] verify commit e0db1d5 * [auto-verifier] verify commit 28b5dd3 * [auto-verifier] verify commit eba0423 * add another test * [auto-verifier] verify commit cb52bd7 * add last test --------- Co-authored-by: GitHub <noreply@github.com>
1 parent 8386f56 commit 67e41c6

File tree

5 files changed

+102
-5
lines changed

5 files changed

+102
-5
lines changed

.verify-helper/timestamps.remote.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
"tests/library_checker_aizu_tests/flow/dinic_aizu.test.cpp": "2024-11-17 14:04:03 -0600",
5151
"tests/library_checker_aizu_tests/flow/hungarian.test.cpp": "2024-11-17 14:04:03 -0600",
5252
"tests/library_checker_aizu_tests/flow/min_cost_max_flow.test.cpp": "2024-12-05 10:41:42 -0600",
53-
"tests/library_checker_aizu_tests/graphs/bcc_callback.test.cpp": "2025-06-23 19:04:08 -0600",
5453
"tests/library_checker_aizu_tests/graphs/biconnected_components.test.cpp": "2025-02-10 23:30:47 -0700",
5554
"tests/library_checker_aizu_tests/graphs/connected_components_of_complement_graph.test.cpp": "2024-12-14 19:50:29 -0600",
5655
"tests/library_checker_aizu_tests/graphs/dijkstra_aizu.test.cpp": "2024-12-14 19:50:29 -0600",
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#define PROBLEM \
2+
"https://onlinejudge.u-aizu.ac.jp/problems/GRL_3_A"
3+
#include "../template.hpp"
4+
#include "../../../library/graphs/bridges_cuts/bcc_callback.hpp"
5+
int main() {
6+
cin.tie(0)->sync_with_stdio(0);
7+
int n, m;
8+
cin >> n >> m;
9+
vector<basic_string<int>> adj(n);
10+
for (int i = 0; i < n; i++) adj[i] += i;
11+
for (int i = 0; i < m; i++) {
12+
int u, v;
13+
cin >> u >> v;
14+
adj[u] += v;
15+
adj[v] += u;
16+
}
17+
vi cnt(n);
18+
bcc_callback(adj, [&](const vi& nodes) {
19+
assert(sz(nodes) >= 2);
20+
for (int v : nodes) cnt[v]++;
21+
});
22+
rep(i, 0, n) if (cnt[i] >= 2) cout << i << '\n';
23+
return 0;
24+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#define PROBLEM \
2+
"https://onlinejudge.u-aizu.ac.jp/problems/GRL_3_B"
3+
#include "../template.hpp"
4+
#include "../../../library/graphs/bridges_cuts/bcc_callback.hpp"
5+
int main() {
6+
cin.tie(0)->sync_with_stdio(0);
7+
int n, m;
8+
cin >> n >> m;
9+
vector<basic_string<int>> adj(n);
10+
for (int i = 0; i < n; i++) adj[i] += i;
11+
for (int i = 0; i < m; i++) {
12+
int u, v;
13+
cin >> u >> v;
14+
adj[u] += v;
15+
adj[v] += u;
16+
}
17+
vector<pii> bridges;
18+
bcc_callback(adj, [&](const vi& nodes) {
19+
assert(sz(nodes) >= 2);
20+
if (sz(nodes) == 2)
21+
bridges.push_back({min(nodes[0], nodes[1]),
22+
max(nodes[0], nodes[1])});
23+
});
24+
ranges::sort(bridges);
25+
for (auto [u, v] : bridges)
26+
cout << u << ' ' << v << endl;
27+
return 0;
28+
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ int main() {
1616
}
1717
vector<bool> vis(n, 0);
1818
vector<vector<int>> all_bccs;
19-
bcc_callback(adj, [&](const vi& nodes_bcc) {
20-
assert(ssize(nodes_bcc) >= 2);
21-
for (int v : nodes_bcc) vis[v] = 1;
22-
all_bccs.push_back(nodes_bcc);
19+
bcc_callback(adj, [&](const vi& nodes) {
20+
assert(ssize(nodes) >= 2);
21+
for (int v : nodes) vis[v] = 1;
22+
all_bccs.push_back(nodes);
2323
});
2424
for (int i = 0; i < n; i++)
2525
if (!vis[i]) all_bccs.push_back({i});
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
UF uf(n);
21+
vector<bool> seen(m);
22+
bcc_callback(adj, [&](const vi& nodes) {
23+
assert(sz(nodes) >= 2);
24+
int cnt_edges = 0;
25+
rep(i, 0, sz(nodes) - 1) for (
26+
int e_id : adj_e_id[nodes[i]]) if (!seen[e_id]) {
27+
seen[e_id] = 1;
28+
cnt_edges++;
29+
}
30+
if (cnt_edges >= 2)
31+
for (int v : nodes) uf.join(v, nodes[0]);
32+
});
33+
vector<basic_string<int>> two_edge_ccs(n);
34+
rep(i, 0, n) two_edge_ccs[uf.find(i)] += i;
35+
int cnt_ccs = 0;
36+
rep(i, 0, n) cnt_ccs += (!empty(two_edge_ccs[i]));
37+
cout << cnt_ccs << '\n';
38+
rep(i, 0, n) {
39+
if (!empty(two_edge_ccs[i])) {
40+
cout << sz(two_edge_ccs[i]) << ' ';
41+
for (int v : two_edge_ccs[i]) cout << v << ' ';
42+
cout << '\n';
43+
}
44+
}
45+
return 0;
46+
}

0 commit comments

Comments
 (0)