Skip to content

Commit cc684ec

Browse files
committed
format
1 parent 6c4a76f commit cc684ec

File tree

14 files changed

+124
-109
lines changed

14 files changed

+124
-109
lines changed

library/graphs/strongly_connected_components/offline_incremental_scc.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
//! @time O((n + m) log m)
1212
//! @space O(n + m)
1313
vi offline_incremental_scc(vector<array<int, 2>> eds,
14-
int n) {
14+
int n) {
1515
int m = sz(eds);
1616
vi ids(n, -1), joins(m, m), idx(m), vs(n), scc_id;
1717
iota(all(idx), 0);
1818
vector<basic_string<int>> adj;
1919
auto divide_and_conquer = [&](auto&& self, auto el,
20-
auto er, int tl, int tr) {
20+
auto er, int tl, int tr) {
2121
adj.clear();
2222
int mid = midpoint(tl, tr);
2323
for (auto it = el; it != er; it++) {

library/math/count_paths/count_paths_triangle.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
vl divide_and_conquer(vl h, vl bottom) {
77
{
88
int start =
9-
ranges::find_if(h, [](ll x) { return x; }) - begin(h);
9+
ranges::find_if(h, [](ll x) { return x; }) -
10+
begin(h);
1011
h.erase(begin(h), begin(h) + start);
1112
bottom.erase(begin(bottom), begin(bottom) + start);
1213
}
@@ -15,10 +16,10 @@ vl divide_and_conquer(vl h, vl bottom) {
1516
if (n == 1) return vl(h[0], bottom[0]);
1617
int mid = n / 2;
1718
auto rect_left =
18-
divide_and_conquer(vl(begin(h), begin(h) + mid),
19-
vl(begin(bottom), begin(bottom) + mid));
19+
divide_and_conquer(vl(begin(h), begin(h) + mid),
20+
vl(begin(bottom), begin(bottom) + mid));
2021
auto [rect_right, rect_top] =
21-
get_right_and_top(rect_left, vl(mid + all(bottom)));
22+
get_right_and_top(rect_left, vl(mid + all(bottom)));
2223
vl h_right(mid + all(h));
2324
for (ll& hh : h_right) hh -= h[mid - 1];
2425
auto upper_right = divide_and_conquer(h_right, rect_top);

library/trees/centroid_decomp_uncommon/count_paths_per_length.hpp

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,35 @@
1010
vector<ll> count_paths_per_length(const vector<vi>& adj) {
1111
vector<ll> num_paths(sz(adj));
1212
centroid(adj,
13-
[&](const vector<vi>& cd_adj, int cent, int) {
14-
vector<vector<double>> child_depths;
15-
for (int v : cd_adj[cent]) {
16-
child_depths.emplace_back(1, 0.0);
17-
for (queue<pii> q({{v, cent}}); !empty(q);) {
18-
child_depths.back().push_back(sz(q));
19-
queue<pii> new_q;
20-
while (!empty(q)) {
21-
auto [u, p] = q.front();
22-
q.pop();
23-
for (int w : cd_adj[u]) {
24-
if (w == p) continue;
25-
new_q.emplace(w, u);
26-
}
27-
}
28-
swap(q, new_q);
29-
}
30-
}
31-
ranges::sort(child_depths, {}, [&](auto& x) { return sz(x); });
32-
vector total_depth(1, 1.0);
33-
for (auto& cnt_depth : child_depths) {
34-
auto prod = conv(total_depth, cnt_depth);
35-
rep(i, 1, sz(prod)) num_paths[i] += llround(prod[i]);
36-
total_depth.resize(sz(cnt_depth));
37-
rep(i, 1, sz(cnt_depth)) total_depth[i] +=
38-
cnt_depth[i];
39-
}
40-
});
13+
[&](const vector<vi>& cd_adj, int cent, int) {
14+
vector<vector<double>> child_depths;
15+
for (int v : cd_adj[cent]) {
16+
child_depths.emplace_back(1, 0.0);
17+
for (queue<pii> q({{v, cent}}); !empty(q);) {
18+
child_depths.back().push_back(sz(q));
19+
queue<pii> new_q;
20+
while (!empty(q)) {
21+
auto [u, p] = q.front();
22+
q.pop();
23+
for (int w : cd_adj[u]) {
24+
if (w == p) continue;
25+
new_q.emplace(w, u);
26+
}
27+
}
28+
swap(q, new_q);
29+
}
30+
}
31+
ranges::sort(child_depths, {},
32+
[&](auto& x) { return sz(x); });
33+
vector total_depth(1, 1.0);
34+
for (auto& cnt_depth : child_depths) {
35+
auto prod = conv(total_depth, cnt_depth);
36+
rep(i, 1, sz(prod)) num_paths[i] +=
37+
llround(prod[i]);
38+
total_depth.resize(sz(cnt_depth));
39+
rep(i, 1, sz(cnt_depth)) total_depth[i] +=
40+
cnt_depth[i];
41+
}
42+
});
4143
return num_paths;
4244
}

library/trees/subtree_isomorphism.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ auto subtree_iso(const auto& adj) {
2222
for (int u : adj[v])
2323
if (u != p) ch_ids.push_back(self(self, u, v));
2424
ranges::sort(ch_ids);
25-
return iso_id[v] = hashes.try_emplace(ch_ids, sz(hashes)).first->second;
25+
return iso_id[v] =
26+
hashes.try_emplace(ch_ids, sz(hashes))
27+
.first->second;
2628
};
2729
rep(i, 0, sz(adj)) if (iso_id[i] == -1) dfs(dfs, i, i);
2830
return pair{sz(hashes), iso_id};

tests/library_checker_aizu_tests/cd_asserts.hpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@ void cd_asserts(const vector<vector<int>>& adj) {
44
vector<int> decomp_size(sz(adj), -1);
55
vector<int> naive_par_decomp(sz(adj), -1);
66
centroid(adj,
7-
[&](const vector<vector<int>>& cd_adj, int cent,
8-
int par_cent) -> void {
9-
assert(naive_par_decomp[cent] == par_cent);
10-
assert(decomp_size[cent] == -1);
11-
auto dfs = [&](auto&& self, int u, int p) -> int {
12-
naive_par_decomp[u] = cent;
13-
int sub_size = 1;
14-
for (int v : cd_adj[u])
15-
if (v != p) sub_size += self(self, v, u);
16-
return sub_size;
17-
};
18-
decomp_size[cent] = dfs(dfs, cent, -1);
19-
if (par_cent != -1)
20-
assert(1 <= decomp_size[cent] &&
21-
2 * decomp_size[cent] <= decomp_size[par_cent]);
22-
for (int u : cd_adj[cent]) {
23-
int sz_subtree = dfs(dfs, u, cent);
24-
assert(1 <= sz_subtree &&
25-
2 * sz_subtree <= decomp_size[cent]);
26-
}
27-
});
7+
[&](const vector<vector<int>>& cd_adj, int cent,
8+
int par_cent) -> void {
9+
assert(naive_par_decomp[cent] == par_cent);
10+
assert(decomp_size[cent] == -1);
11+
auto dfs = [&](auto&& self, int u, int p) -> int {
12+
naive_par_decomp[u] = cent;
13+
int sub_size = 1;
14+
for (int v : cd_adj[u])
15+
if (v != p) sub_size += self(self, v, u);
16+
return sub_size;
17+
};
18+
decomp_size[cent] = dfs(dfs, cent, -1);
19+
if (par_cent != -1)
20+
assert(1 <= decomp_size[cent] &&
21+
2 * decomp_size[cent] <= decomp_size[par_cent]);
22+
for (int u : cd_adj[cent]) {
23+
int sz_subtree = dfs(dfs, u, cent);
24+
assert(1 <= sz_subtree &&
25+
2 * sz_subtree <= decomp_size[cent]);
26+
}
27+
});
2828
rep(i, 0, sz(adj)) assert(decomp_size[i] >= 1);
2929
}

tests/library_checker_aizu_tests/data_structures/range_parallel_dsu.test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ int main() {
3030
dsu.join(a, b, k, f);
3131
queries.push_back({a, b, k});
3232
cout << ans.x << '\n';
33-
if (qq == 0 || qq == 1 || qq == 10 || qq == 1000 || qq == 100'000 || qq == q - 1) {
33+
if (qq == 0 || qq == 1 || qq == 10 || qq == 1000 ||
34+
qq == 100'000 || qq == q - 1) {
3435
auto uf = get_rp_dsu(queries, n);
3536
vector<mint> sums(n);
3637
mint offline_ans = 0;

tests/library_checker_aizu_tests/data_structures/rmq_linear.test.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,20 @@ int main() {
1717
int l, r;
1818
cin >> l >> r;
1919
int idx_right_min = rmq_less.query_idx(l, r - 1);
20-
assert(idx_right_min + 1 == r || rmq_less.query(idx_right_min + 1, r - 1) > a[idx_right_min]);
20+
assert(idx_right_min + 1 == r ||
21+
rmq_less.query(idx_right_min + 1, r - 1) >
22+
a[idx_right_min]);
2123
assert(l <= idx_right_min && idx_right_min < r);
2224
assert(rmq_less.query(l, r - 1) == a[idx_right_min]);
23-
assert(idx_right_min == rmq_greater.query_idx(l, r - 1));
25+
assert(
26+
idx_right_min == rmq_greater.query_idx(l, r - 1));
2427
int idx_left_min = rmq_less_equal.query_idx(l, r - 1);
25-
assert(l == idx_left_min || rmq_less_equal.query(l, idx_left_min - 1) > a[idx_left_min]);
28+
assert(l == idx_left_min ||
29+
rmq_less_equal.query(l, idx_left_min - 1) >
30+
a[idx_left_min]);
2631
assert(l <= idx_left_min && idx_left_min < r);
27-
assert(idx_left_min == rmq_greater_equal.query_idx(l, r - 1));
32+
assert(idx_left_min ==
33+
rmq_greater_equal.query_idx(l, r - 1));
2834
assert(a[idx_right_min] == a[idx_left_min]);
2935
assert(idx_left_min <= idx_right_min);
3036
cout << a[idx_right_min] << '\n';

tests/library_checker_aizu_tests/graphs/offline_incremental_scc.test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ int main() {
1818
assert((eds[t][0] == eds[t][1]) == (joins[t] == -1));
1919
vector<int> order(m);
2020
iota(all(order), 0);
21-
ranges::sort(all(order), {}, [&](int i) { return joins[i]; });
21+
ranges::sort(all(order), {},
22+
[&](int i) { return joins[i]; });
2223
UF uf(n);
2324
mint sum = 0;
2425
for (int t = 0, it = 0; t < m; t++) {

tests/library_checker_aizu_tests/handmade_tests/count_paths_forest.test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include "../../../library/trees/centroid_decomp_uncommon/count_paths_per_length.hpp"
99
#include "../cd_asserts.hpp"
1010
vector<vector<ll>> naive(const vector<vector<int>>& adj,
11-
dsu_restorable& dsu) {
11+
dsu_restorable& dsu) {
1212
tree_lift tl(adj);
1313
int n = sz(adj);
1414
vector<vector<ll>> cnts_naive(n + 1, vector<ll>(n, 0));
@@ -42,13 +42,13 @@ int main() {
4242
vector<vector<ll>> cnts_naive = naive(adj, dsu);
4343
for (int k = 1; k <= n; k++)
4444
assert(
45-
count_paths_per_node(adj, k) == cnts_naive[k]);
45+
count_paths_per_node(adj, k) == cnts_naive[k]);
4646
vector<ll> num_paths_len = count_paths_per_length(adj);
4747
for (int k = 1; k < n; k++) {
4848
vector<ll> count_paths =
49-
count_paths_per_node(adj, k);
49+
count_paths_per_node(adj, k);
5050
ll total_paths = accumulate(begin(count_paths),
51-
end(count_paths), 0LL);
51+
end(count_paths), 0LL);
5252
assert(total_paths % (k + 1) == 0);
5353
total_paths /= k + 1;
5454
assert(num_paths_len[k] == total_paths);

tests/library_checker_aizu_tests/handmade_tests/edge_cd_small_trees.test.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ int main() {
99
{
1010
vector<vector<int>> adj;
1111
edge_cd(adj,
12-
[&](const vector<vector<int>>&, int, int) -> void {
13-
assert(false);
14-
});
12+
[&](const vector<vector<int>>&, int, int) -> void {
13+
assert(false);
14+
});
1515
}
1616
{
1717
vector<vector<int>> adj(1);
1818
edge_cd(adj,
19-
[&](const vector<vector<int>>&, int, int) -> void {
20-
assert(false);
21-
});
19+
[&](const vector<vector<int>>&, int, int) -> void {
20+
assert(false);
21+
});
2222
}
2323
for (int n = 2; n <= 7; n++) {
2424
int num_codes = mpow(n, n - 2).x;
2525
vector<vector<int>> pruf_codes(num_codes,
26-
vector<int>(n - 2));
26+
vector<int>(n - 2));
2727
for (int i = 0; i < num_codes; i++) {
2828
int val = i;
2929
for (int j = 0; j < n - 2; j++) {

0 commit comments

Comments
 (0)