diff --git a/.verify-helper/timestamps.remote.json b/.verify-helper/timestamps.remote.json index 720f8d32..78589294 100644 --- a/.verify-helper/timestamps.remote.json +++ b/.verify-helper/timestamps.remote.json @@ -50,7 +50,6 @@ "tests/library_checker_aizu_tests/flow/dinic_aizu.test.cpp": "2024-11-17 14:04:03 -0600", "tests/library_checker_aizu_tests/flow/hungarian.test.cpp": "2024-11-17 14:04:03 -0600", "tests/library_checker_aizu_tests/flow/min_cost_max_flow.test.cpp": "2024-12-05 10:41:42 -0600", -"tests/library_checker_aizu_tests/graphs/bcc_callback.test.cpp": "2025-06-23 19:04:08 -0600", "tests/library_checker_aizu_tests/graphs/biconnected_components.test.cpp": "2025-02-10 23:30:47 -0700", "tests/library_checker_aizu_tests/graphs/connected_components_of_complement_graph.test.cpp": "2024-12-14 19:50:29 -0600", "tests/library_checker_aizu_tests/graphs/dijkstra_aizu.test.cpp": "2024-12-14 19:50:29 -0600", diff --git a/tests/library_checker_aizu_tests/graphs/bcc_callback_aizu_bcc.test.cpp b/tests/library_checker_aizu_tests/graphs/bcc_callback_aizu_bcc.test.cpp new file mode 100644 index 00000000..70145914 --- /dev/null +++ b/tests/library_checker_aizu_tests/graphs/bcc_callback_aizu_bcc.test.cpp @@ -0,0 +1,24 @@ +#define PROBLEM \ + "https://onlinejudge.u-aizu.ac.jp/problems/GRL_3_A" +#include "../template.hpp" +#include "../../../library/graphs/bridges_cuts/bcc_callback.hpp" +int main() { + cin.tie(0)->sync_with_stdio(0); + int n, m; + cin >> n >> m; + vector> adj(n); + for (int i = 0; i < n; i++) adj[i] += i; + for (int i = 0; i < m; i++) { + int u, v; + cin >> u >> v; + adj[u] += v; + adj[v] += u; + } + vi cnt(n); + bcc_callback(adj, [&](const vi& nodes) { + assert(sz(nodes) >= 2); + for (int v : nodes) cnt[v]++; + }); + rep(i, 0, n) if (cnt[i] >= 2) cout << i << '\n'; + return 0; +} diff --git a/tests/library_checker_aizu_tests/graphs/bcc_callback_aizu_two_edge_cc.test.cpp b/tests/library_checker_aizu_tests/graphs/bcc_callback_aizu_two_edge_cc.test.cpp new file mode 100644 index 00000000..f655d4cb --- /dev/null +++ b/tests/library_checker_aizu_tests/graphs/bcc_callback_aizu_two_edge_cc.test.cpp @@ -0,0 +1,28 @@ +#define PROBLEM \ + "https://onlinejudge.u-aizu.ac.jp/problems/GRL_3_B" +#include "../template.hpp" +#include "../../../library/graphs/bridges_cuts/bcc_callback.hpp" +int main() { + cin.tie(0)->sync_with_stdio(0); + int n, m; + cin >> n >> m; + vector> adj(n); + for (int i = 0; i < n; i++) adj[i] += i; + for (int i = 0; i < m; i++) { + int u, v; + cin >> u >> v; + adj[u] += v; + adj[v] += u; + } + vector bridges; + bcc_callback(adj, [&](const vi& nodes) { + assert(sz(nodes) >= 2); + if (sz(nodes) == 2) + bridges.push_back({min(nodes[0], nodes[1]), + max(nodes[0], nodes[1])}); + }); + ranges::sort(bridges); + for (auto [u, v] : bridges) + cout << u << ' ' << v << endl; + return 0; +} diff --git a/tests/library_checker_aizu_tests/graphs/bcc_callback.test.cpp b/tests/library_checker_aizu_tests/graphs/bcc_callback_lib_checker_bcc.test.cpp similarity index 83% rename from tests/library_checker_aizu_tests/graphs/bcc_callback.test.cpp rename to tests/library_checker_aizu_tests/graphs/bcc_callback_lib_checker_bcc.test.cpp index 2dffc95a..9dd2bfd0 100644 --- a/tests/library_checker_aizu_tests/graphs/bcc_callback.test.cpp +++ b/tests/library_checker_aizu_tests/graphs/bcc_callback_lib_checker_bcc.test.cpp @@ -16,10 +16,10 @@ int main() { } vector vis(n, 0); vector> all_bccs; - bcc_callback(adj, [&](const vi& nodes_bcc) { - assert(ssize(nodes_bcc) >= 2); - for (int v : nodes_bcc) vis[v] = 1; - all_bccs.push_back(nodes_bcc); + bcc_callback(adj, [&](const vi& nodes) { + assert(ssize(nodes) >= 2); + for (int v : nodes) vis[v] = 1; + all_bccs.push_back(nodes); }); for (int i = 0; i < n; i++) if (!vis[i]) all_bccs.push_back({i}); diff --git a/tests/library_checker_aizu_tests/graphs/bcc_callback_lib_checker_two_cc.test.cpp b/tests/library_checker_aizu_tests/graphs/bcc_callback_lib_checker_two_cc.test.cpp new file mode 100644 index 00000000..200fb98f --- /dev/null +++ b/tests/library_checker_aizu_tests/graphs/bcc_callback_lib_checker_two_cc.test.cpp @@ -0,0 +1,46 @@ +#define PROBLEM \ + "https://judge.yosupo.jp/problem/two_edge_connected_components" +#include "../template.hpp" +#include "../../../library/graphs/bridges_cuts/bcc_callback.hpp" +#include "../../../kactl/content/data-structures/UnionFind.h" +int main() { + cin.tie(0)->sync_with_stdio(0); + int n, m; + cin >> n >> m; + vector> adj(n), adj_e_id(n); + for (int i = 0; i < n; i++) adj[i] += i; + for (int i = 0; i < m; i++) { + int u, v; + cin >> u >> v; + adj[u] += v; + adj[v] += u; + adj_e_id[u] += i; + adj_e_id[v] += i; + } + UF uf(n); + vector seen(m); + bcc_callback(adj, [&](const vi& nodes) { + assert(sz(nodes) >= 2); + int cnt_edges = 0; + rep(i, 0, sz(nodes) - 1) for ( + int e_id : adj_e_id[nodes[i]]) if (!seen[e_id]) { + seen[e_id] = 1; + cnt_edges++; + } + if (cnt_edges >= 2) + for (int v : nodes) uf.join(v, nodes[0]); + }); + vector> two_edge_ccs(n); + rep(i, 0, n) two_edge_ccs[uf.find(i)] += i; + int cnt_ccs = 0; + rep(i, 0, n) cnt_ccs += (!empty(two_edge_ccs[i])); + cout << cnt_ccs << '\n'; + rep(i, 0, n) { + if (!empty(two_edge_ccs[i])) { + cout << sz(two_edge_ccs[i]) << ' '; + for (int v : two_edge_ccs[i]) cout << v << ' '; + cout << '\n'; + } + } + return 0; +}