Skip to content

Commit 809440e

Browse files
lrvideckisweb-flow
andauthored
lots of nits (#188)
* lots of nits * [auto-verifier] verify commit b9ac2cf * more nits * even more nits * [auto-verifier] verify commit 2cba688 * nits/golf * [auto-verifier] verify commit 854f12e * update * fix * another fix --------- Co-authored-by: GitHub <noreply@github.com>
1 parent 99c9cd2 commit 809440e

14 files changed

Lines changed: 76 additions & 83 deletions

.verify-helper/timestamps.remote.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,20 @@
1818
"tests/library_checker_aizu_tests/data_structures/disjoint_rmq_inc_lines.test.cpp": "2026-01-18 11:15:41 +0000",
1919
"tests/library_checker_aizu_tests/data_structures/disjoint_rmq_inc_sum.test.cpp": "2026-01-18 11:15:41 +0000",
2020
"tests/library_checker_aizu_tests/data_structures/distinct_query.test.cpp": "2026-01-18 11:15:41 +0000",
21-
"tests/library_checker_aizu_tests/data_structures/dsu.test.cpp": "2026-01-22 10:08:22 -0700",
22-
"tests/library_checker_aizu_tests/data_structures/dsu_bipartite.test.cpp": "2026-01-18 02:20:40 +0000",
2321
"tests/library_checker_aizu_tests/data_structures/implicit_seg_tree.test.cpp": "2026-01-18 11:15:41 +0000",
2422
"tests/library_checker_aizu_tests/data_structures/kd_bit_1d.test.cpp": "2026-02-19 18:06:52 -0700",
25-
"tests/library_checker_aizu_tests/data_structures/kruskal_tree_aizu.test.cpp": "2026-01-18 02:20:40 +0000",
2623
"tests/library_checker_aizu_tests/data_structures/kth_smallest_pst.test.cpp": "2026-01-18 11:15:41 +0000",
2724
"tests/library_checker_aizu_tests/data_structures/kth_smallest_wavelet_matrix.test.cpp": "2026-02-04 02:50:53 +0000",
2825
"tests/library_checker_aizu_tests/data_structures/lazy_segment_tree.test.cpp": "2026-01-23 04:31:29 +0000",
2926
"tests/library_checker_aizu_tests/data_structures/lazy_segment_tree_constructor.test.cpp": "2026-01-23 04:31:29 +0000",
3027
"tests/library_checker_aizu_tests/data_structures/lazy_segment_tree_inc.test.cpp": "2026-02-05 13:02:29 -0700",
3128
"tests/library_checker_aizu_tests/data_structures/lazy_segment_tree_inc_constructor.test.cpp": "2026-02-05 13:02:29 -0700",
32-
"tests/library_checker_aizu_tests/data_structures/line_tree_aizu.test.cpp": "2026-01-18 11:15:41 +0000",
33-
"tests/library_checker_aizu_tests/data_structures/line_tree_lib_checker.test.cpp": "2026-01-18 02:20:40 +0000",
3429
"tests/library_checker_aizu_tests/data_structures/merge_sort_tree.test.cpp": "2026-01-18 11:04:58 +0000",
3530
"tests/library_checker_aizu_tests/data_structures/mode_query.test.cpp": "2026-01-18 02:20:40 +0000",
3631
"tests/library_checker_aizu_tests/data_structures/permutation_tree.test.cpp": "2026-01-18 11:15:41 +0000",
3732
"tests/library_checker_aizu_tests/data_structures/persistent_queue_tree.test.cpp": "2026-01-18 11:15:41 +0000",
3833
"tests/library_checker_aizu_tests/data_structures/persistent_seg_tree.test.cpp": "2026-01-18 11:15:41 +0000",
3934
"tests/library_checker_aizu_tests/data_structures/pq_ds_undo_sliding_window.test.cpp": "2026-01-18 02:20:40 +0000",
40-
"tests/library_checker_aizu_tests/data_structures/range_parallel_dsu.test.cpp": "2026-01-22 10:08:22 -0700",
4135
"tests/library_checker_aizu_tests/data_structures/rmq_linear.test.cpp": "2026-01-18 11:15:41 +0000",
4236
"tests/library_checker_aizu_tests/data_structures/rmq_sparse_table.test.cpp": "2026-01-18 11:15:41 +0000",
4337
"tests/library_checker_aizu_tests/data_structures/rmq_sparse_table_inc.test.cpp": "2026-01-18 11:15:41 +0000",
@@ -47,6 +41,12 @@
4741
"tests/library_checker_aizu_tests/data_structures/simple_tree_inc_walk.test.cpp": "2026-02-16 16:56:58 -0700",
4842
"tests/library_checker_aizu_tests/data_structures/simple_tree_line.test.cpp": "2026-02-14 20:58:21 +0000",
4943
"tests/library_checker_aizu_tests/data_structures/simple_tree_walk.test.cpp": "2026-02-14 20:58:21 +0000",
44+
"tests/library_checker_aizu_tests/dsu/dsu.test.cpp": "2026-02-27 11:50:42 -0700",
45+
"tests/library_checker_aizu_tests/dsu/dsu_bipartite.test.cpp": "2026-02-27 11:58:10 -0700",
46+
"tests/library_checker_aizu_tests/dsu/kruskal_tree_aizu.test.cpp": "2026-02-27 11:50:42 -0700",
47+
"tests/library_checker_aizu_tests/dsu/line_tree_aizu.test.cpp": "2026-02-27 11:56:18 -0700",
48+
"tests/library_checker_aizu_tests/dsu/line_tree_lib_checker.test.cpp": "2026-02-27 11:56:18 -0700",
49+
"tests/library_checker_aizu_tests/dsu/range_parallel_dsu.test.cpp": "2026-02-27 14:31:41 -0700",
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",

library/dsu/dsu_bipartite.hpp

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,28 @@
33
//! DSU with support for parity of path to root for online
44
//! bipartite check
55
struct dsu_bipartite {
6-
int num_sets;
76
vi p, is_bi, parity;
8-
dsu_bipartite(int n):
9-
num_sets(n), p(n, -1), is_bi(n, 1), parity(n) {}
10-
int find(int v) {
7+
dsu_bipartite(int n): p(n, -1), is_bi(n, 1), parity(n) {}
8+
int f(int v) {
119
if (p[v] < 0) return v;
12-
int root = find(p[v]);
10+
int root = f(p[v]);
1311
parity[v] ^= parity[p[v]];
1412
return p[v] = root;
1513
}
1614
bool join(int u, int v) {
17-
int root_u = find(u), root_v = find(v);
18-
if (root_u == root_v) {
19-
if (parity[u] == parity[v]) is_bi[root_u] = 0;
15+
int root_u = f(u), root_v = f(v);
16+
int new_parity = parity[v] ^ parity[u];
17+
u = root_u, v = root_v;
18+
if (u == v) {
19+
is_bi[u] &= new_parity;
2020
return 0;
2121
}
22-
if (p[root_u] > p[root_v]) {
23-
swap(u, v);
24-
swap(root_u, root_v);
25-
}
26-
is_bi[root_u] &= is_bi[root_v];
27-
parity[root_v] = parity[v] ^ 1 ^ parity[u];
28-
p[root_u] += p[root_v], p[root_v] = root_u, num_sets--;
22+
if (p[u] > p[v]) swap(u, v);
23+
is_bi[u] &= is_bi[v];
24+
parity[v] = new_parity ^ 1;
25+
p[u] += p[v], p[v] = u;
2926
return 1;
3027
}
31-
int size(int v) { return -p[find(v)]; }
32-
bool same_set(int u, int v) {
33-
return find(u) == find(v);
34-
}
35-
bool is_bipartite(int v) { return is_bi[find(v)]; }
28+
int size(int v) { return -p[f(v)]; }
29+
bool is_bipartite(int v) { return is_bi[f(v)]; }
3630
};

library/dsu/kruskal_tree.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ struct kr_tree {
77
vi p;
88
vector<vi> adj;
99
kr_tree(int n): id(n), p(2 * n, -1), adj(2 * n) {}
10-
int find(int v) {
11-
return p[v] < 0 ? v : p[v] = find(p[v]);
12-
}
10+
int f(int v) { return p[v] < 0 ? v : p[v] = f(p[v]); }
1311
bool join(int u, int v) {
14-
if ((u = find(u)) == (v = find(v))) return 0;
12+
if ((u = f(u)) == (v = f(v))) return 0;
1513
return adj[p[u] = p[v] = id++] = {u, v}, 1;
1614
}
1715
};

library/dsu/line_tree.hpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
//! ranges::sort(w_eds);
55
//! line_tree lt(n);
66
//! for (auto [w, u, v] : w_eds) lt.join(u, v);
7-
//! for (int v = lt.find(0); v != -1;) {
7+
//! for (int v = lt.f(0); v != -1;) {
88
//! auto [next, e_id] = lt.edge[v];
99
//! int w = w_eds[e_id][0];
1010
//! //
1111
//! v = next;
1212
//! }
1313
//! @endcode
14-
//! lt.find(v) = head of linked list
14+
//! lt.f(v) = head of linked list
1515
//! of component containing v
1616
//! @time O(n + m * \alpha(n))
1717
//! @space O(n + m)
@@ -22,16 +22,14 @@ struct line_tree {
2222
line_tree(int n): p(n, -1), last(n), edge(n, {-1, -1}) {
2323
iota(all(last), 0);
2424
}
25-
int size(int v) { return -p[find(v)]; }
26-
int find(int v) {
27-
return p[v] < 0 ? v : p[v] = find(p[v]);
28-
}
25+
int size(int v) { return -p[f(v)]; }
26+
int f(int v) { return p[v] < 0 ? v : p[v] = f(p[v]); }
2927
bool join(int u, int v) {
30-
u = find(u), v = find(v), id++;
28+
u = f(u), v = f(v), id++;
3129
if (u == v) return 0;
3230
if (p[u] < p[v]) swap(u, v);
3331
p[v] += p[u], p[u] = v;
34-
edge[exchange(last[v], last[u])] = {u, id - 1};
32+
edge[last[v]] = {u, id - 1}, last[v] = last[u];
3533
return 1;
3634
}
3735
};

library/dsu/range_parallel_dsu.hpp

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
11
#pragma once
22
#include "dsu.hpp"
3-
//! Given l1,l2,len; joins (l1,l2), (l1+1,l2+1),
4-
//! ..., (l1+len-1,l2+len-1)
3+
//! Given u,v,len; joins (u,v), (u+1,v+1),
4+
//! ..., (u+len-1,v+len-1)
55
//! `f` is called at most n-1 times
66
//! @time O(n*log(n)*\alpha(n) + q)
77
//! @space O(n log n)
88
struct rp_dsu {
99
vector<DSU> dsus;
10-
rp_dsu(int n): dsus(bit_width(unsigned(n)), DSU(n)) {}
11-
void join(int l1, int l2, int len, const auto& f) {
12-
if (len == 0) return;
13-
int lg = __lg(len);
14-
join_impl(lg, l1, l2, f);
15-
join_impl(lg, l1 + len - (1 << lg),
16-
l2 + len - (1 << lg), f);
10+
rp_dsu(int n): dsus(bit_width(n + 0u), DSU(n)) {}
11+
void join(int u, int v, int len, const auto& f) {
12+
int i = __lg(len);
13+
join(u, v, f, i);
14+
join(u + len - (1 << i), v + len - (1 << i), f, i);
1715
}
18-
void join_impl(int lvl, int u, int v, const auto& f) {
19-
if (lvl == 0) {
20-
u = dsus[0].f(u);
21-
v = dsus[0].f(v);
22-
if (!dsus[0].join(v, u)) return;
23-
int w = dsus[0].f(u);
24-
return f(w, u ^ v ^ w);
25-
}
26-
if (!dsus[lvl].join(u, v)) return;
27-
join_impl(lvl - 1, u, v, f);
28-
join_impl(lvl - 1, u + (1 << (lvl - 1)),
29-
v + (1 << (lvl - 1)), f);
16+
void join(int u, int v, const auto& f, int i) {
17+
if (!dsus[i].join(u, v)) return;
18+
if (i == 0) return f(u, v);
19+
i--;
20+
join(u, v, f, i);
21+
join(u + (1 << i), v + (1 << i), f, i);
3022
}
3123
};
Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
#pragma once
22
#include "dsu.hpp"
3-
//! Given triplets (l1,l2,len); joins (l1,l2),
4-
//! (l1+1,l2+1), ..., (l1+len-1,l2+len-1)
3+
//! @code
4+
//! vector<vector<pii>> joins(n + 1);
5+
//! joins[len].emplace_back(u, v);
6+
//! // it does:
7+
//! // dsu.join(u + 0, v + 0);
8+
//! // dsu.join(u + 1, v + 1);
9+
//! // dsu.join(u + 2, v + 2);
10+
//! // ...
11+
//! // dsu.join(u + len - 1, v + len - 1);
12+
//! DSU dsu = get_rp_dsu(joins, n);
13+
//! @endcode
514
//! @time O((n + q) * \alpha(n))
615
//! @space O(n + q)
7-
DSU get_rp_dsu(const vector<array<int, 3>>& rests, int n) {
8-
vector<vector<pii>> rests_by_len(n + 1);
9-
for (auto [l1, l2, len] : rests)
10-
rests_by_len[len].emplace_back(l1, l2);
16+
DSU get_rp_dsu(vector<vector<pii>>& joins, int n) {
1117
DSU dsu(n);
12-
for (int len = n; len > 0; len--)
13-
for (auto [l1, l2] : rests_by_len[len])
14-
if (dsu.join(l1, l2))
15-
rests_by_len[len - 1].emplace_back(l1 + 1, l2 + 1);
18+
for (int i = n; i; i--)
19+
for (auto [u, v] : joins[i])
20+
if (dsu.join(u, v))
21+
joins[i - 1].emplace_back(u + 1, v + 1);
1622
return dsu;
1723
}

tests/.config/.cppcheck_suppression_list

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ syntaxError:../library/math/prime_sieve/mobius.hpp:6
4141
syntaxError:../library/trees/lca_rmq/iterate_subtree.hpp:6
4242
knownConditionTrueFalse:../library/strings/suffix_array/suffix_array.hpp:62
4343
knownConditionTrueFalse:../library/strings/suffix_array/suffix_array_short.hpp:34
44-
knownConditionTrueFalse:../library/dsu/kruskal_tree.hpp:15
44+
knownConditionTrueFalse:../library/dsu/kruskal_tree.hpp:13
4545
knownConditionTrueFalse:../library/dsu/dsu.hpp:11
4646
constVariable:../kactl/content/numerical/NumberTheoreticTransform.h:30
4747
constVariable:../kactl/content/graph/CompressTree.h:20

tests/library_checker_aizu_tests/data_structures/dsu.test.cpp renamed to tests/library_checker_aizu_tests/dsu/dsu.test.cpp

File renamed without changes.

tests/library_checker_aizu_tests/data_structures/dsu_bipartite.test.cpp renamed to tests/library_checker_aizu_tests/dsu/dsu_bipartite.test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ int main() {
4242
dsu.join(u, v);
4343
adj[u].push_back(v);
4444
adj[v].push_back(u);
45-
} else cout << dsu.same_set(u, v) << '\n';
46-
if (rnd<int>(0, 20'000) == 0) check();
45+
} else cout << (dsu.f(u) == dsu.f(v)) << '\n';
46+
if (i <= 20 || rnd<int>(0, 20'000) == 0) check();
4747
}
4848
check();
4949
return 0;

tests/library_checker_aizu_tests/data_structures/kruskal_tree_aizu.test.cpp renamed to tests/library_checker_aizu_tests/dsu/kruskal_tree_aizu.test.cpp

File renamed without changes.

0 commit comments

Comments
 (0)