Skip to content

Commit b70cd4f

Browse files
lrvideckisweb-flow
andauthored
Shallowest decomp tree (#160)
* shallowest decomp tree * [auto-verifier] verify commit 41b4a59 * nits * [auto-verifier] verify commit b04851b * revert constexpr -> const as it was causing build issues * fix --------- Co-authored-by: GitHub <noreply@github.com>
1 parent 1eb2ee7 commit b70cd4f

File tree

18 files changed

+99
-22
lines changed

18 files changed

+99
-22
lines changed

.verify-helper/timestamps.remote.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,6 @@
144144
"tests/library_checker_aizu_tests/trees/kth_path_tree_lift.test.cpp": "2025-08-14 10:27:46 -0600",
145145
"tests/library_checker_aizu_tests/trees/lca_all_methods_aizu.test.cpp": "2025-08-21 12:17:27 -0600",
146146
"tests/library_checker_aizu_tests/trees/lca_all_methods_lib_checker.test.cpp": "2025-08-21 12:17:27 -0600",
147+
"tests/library_checker_aizu_tests/trees/shallowest_aizu_tree_height.test.cpp": "2025-08-28 13:09:33 -0600",
147148
"tests/library_checker_aizu_tests/trees/subtree_isomorphism.test.cpp": "2025-08-14 10:27:46 -0600"
148149
}

library/convolution/gcd_convolution.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//! for all pairs (i,j) where gcd(i,j)==k
88
//! @time O(n log n)
99
//! @space O(n)
10-
constexpr int mod = 998'244'353;
10+
const int mod = 998'244'353;
1111
vi gcd_convolution(const vi& a, const vi& b) {
1212
int n = sz(a);
1313
vi c(n);

library/convolution/lcm_convolution.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//! for all pairs (i,j) where lcm(i,j)==k
88
//! @time O(n log n)
99
//! @space O(n)
10-
constexpr int mod = 998'244'353;
10+
const int mod = 998'244'353;
1111
vi lcm_convolution(const vi& a, const vi& b) {
1212
int n = sz(a);
1313
vector<ll> sum_a(n), sum_b(n);

library/data_structures/seg_tree_uncommon/implicit.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ template<int N> struct implicit_seg_tree {
88
if (l[0] == r[0]) return {l[0], l[1] + r[1]};
99
return min(l, r);
1010
}
11-
static constexpr dt unit{LLONG_MAX, 0LL};
11+
const dt unit{LLONG_MAX, 0LL};
1212
struct node {
1313
dt num;
1414
ll lazy = 0;

library/math/fibonacci.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! @endcode
1212
//! @time O(log n)
1313
//! @space O(log n)
14-
constexpr int mod = 998'244'353;
14+
const int mod = 998'244'353;
1515
array<ll, 2> fib(ll n) {
1616
if (n == 0) return {0LL, 1LL};
1717
auto [x, y] = fib(n >> 1);

library/math/mod_int.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#pragma once
2-
constexpr int mod = 998244353;
2+
const int mod = 998244353;
33
//! https://github.com/kth-competitive-programming/kactl/blob/main/content/number-theory/ModularArithmetic.h
44
//! https://codeforces.com/blog/entry/122714
55
struct mint {

library/math/n_choose_k/grow.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#pragma once
2-
constexpr int mod = 17; //!< must be prime
2+
const int mod = 17; //!< must be prime
33
struct comb {
44
ll inv = 1, fact = 1, inv_fact = 1;
55
};

library/math/n_choose_k/pascals_identity.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#pragma once
2-
constexpr int mod = 17; //!< composite ok
2+
const int mod = 17; //!< composite ok
33
vector<vector<ll>> ch(1010); //!< ch[n][k] = n choose k
44
rep(i, 0, sz(ch)) {
55
ch[i].resize(i + 1, 1);

library/math/partitions.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#pragma once
2-
constexpr int mod = 998'244'353;
2+
const int mod = 998'244'353;
33
//! https://oeis.org/A000041
44
//! @code
55
//! auto p = partitions(n);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma once
2+
//! https://codeforces.com/blog/entry/125018
3+
//! @code
4+
//! vector<basic_string<int>> adj(n);
5+
//! shallowest(adj, [&](int cent) {
6+
//! });
7+
//! @endcode
8+
//! @time O(n log n)
9+
//! @space O(n)
10+
void shallowest(auto& adj, auto f) {
11+
vector<vi> order(bit_width(size(adj)));
12+
auto dfs = [&](auto&& self, int v, int p) -> int {
13+
int once = 0, twice = 0;
14+
for (int u : adj[v])
15+
if (u != p) {
16+
int dp = self(self, u, v);
17+
twice |= once & dp, once |= dp;
18+
}
19+
auto dp = (once | (bit_ceil(twice + 1u) - 1)) + 1;
20+
order[countr_zero(dp)].push_back(v);
21+
return dp;
22+
};
23+
dfs(dfs, 0, 0);
24+
for (const auto& vec : order | views::reverse)
25+
for (int v : vec) {
26+
f(v);
27+
for (int u : adj[v])
28+
iter_swap(ranges::find(adj[u], v), rbegin(adj[u])),
29+
adj[u].pop_back();
30+
}
31+
}

0 commit comments

Comments
 (0)