Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .verify-helper/timestamps.remote.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,6 @@
"tests/library_checker_aizu_tests/trees/kth_path_tree_lift.test.cpp": "2025-08-14 10:27:46 -0600",
"tests/library_checker_aizu_tests/trees/lca_all_methods_aizu.test.cpp": "2025-08-21 12:17:27 -0600",
"tests/library_checker_aizu_tests/trees/lca_all_methods_lib_checker.test.cpp": "2025-08-21 12:17:27 -0600",
"tests/library_checker_aizu_tests/trees/shallowest_aizu_tree_height.test.cpp": "2025-08-28 13:09:33 -0600",
"tests/library_checker_aizu_tests/trees/subtree_isomorphism.test.cpp": "2025-08-14 10:27:46 -0600"
}
2 changes: 1 addition & 1 deletion library/convolution/gcd_convolution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! for all pairs (i,j) where gcd(i,j)==k
//! @time O(n log n)
//! @space O(n)
constexpr int mod = 998'244'353;
const int mod = 998'244'353;
vi gcd_convolution(const vi& a, const vi& b) {
int n = sz(a);
vi c(n);
Expand Down
2 changes: 1 addition & 1 deletion library/convolution/lcm_convolution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! for all pairs (i,j) where lcm(i,j)==k
//! @time O(n log n)
//! @space O(n)
constexpr int mod = 998'244'353;
const int mod = 998'244'353;
vi lcm_convolution(const vi& a, const vi& b) {
int n = sz(a);
vector<ll> sum_a(n), sum_b(n);
Expand Down
2 changes: 1 addition & 1 deletion library/data_structures/seg_tree_uncommon/implicit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ template<int N> struct implicit_seg_tree {
if (l[0] == r[0]) return {l[0], l[1] + r[1]};
return min(l, r);
}
static constexpr dt unit{LLONG_MAX, 0LL};
const dt unit{LLONG_MAX, 0LL};
struct node {
dt num;
ll lazy = 0;
Expand Down
2 changes: 1 addition & 1 deletion library/math/fibonacci.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! @endcode
//! @time O(log n)
//! @space O(log n)
constexpr int mod = 998'244'353;
const int mod = 998'244'353;
array<ll, 2> fib(ll n) {
if (n == 0) return {0LL, 1LL};
auto [x, y] = fib(n >> 1);
Expand Down
2 changes: 1 addition & 1 deletion library/math/mod_int.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
constexpr int mod = 998244353;
const int mod = 998244353;
//! https://github.com/kth-competitive-programming/kactl/blob/main/content/number-theory/ModularArithmetic.h
//! https://codeforces.com/blog/entry/122714
struct mint {
Expand Down
2 changes: 1 addition & 1 deletion library/math/n_choose_k/grow.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
constexpr int mod = 17; //!< must be prime
const int mod = 17; //!< must be prime
struct comb {
ll inv = 1, fact = 1, inv_fact = 1;
};
Expand Down
2 changes: 1 addition & 1 deletion library/math/n_choose_k/pascals_identity.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
constexpr int mod = 17; //!< composite ok
const int mod = 17; //!< composite ok
vector<vector<ll>> ch(1010); //!< ch[n][k] = n choose k
rep(i, 0, sz(ch)) {
ch[i].resize(i + 1, 1);
Expand Down
2 changes: 1 addition & 1 deletion library/math/partitions.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
constexpr int mod = 998'244'353;
const int mod = 998'244'353;
//! https://oeis.org/A000041
//! @code
//! auto p = partitions(n);
Expand Down
31 changes: 31 additions & 0 deletions library/trees/shallowest_decomp_tree.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once
//! https://codeforces.com/blog/entry/125018
//! @code
//! vector<basic_string<int>> adj(n);
//! shallowest(adj, [&](int cent) {
//! });
//! @endcode
//! @time O(n log n)
//! @space O(n)
void shallowest(auto& adj, auto f) {
vector<vi> order(bit_width(size(adj)));
auto dfs = [&](auto&& self, int v, int p) -> int {
int once = 0, twice = 0;
for (int u : adj[v])
if (u != p) {
int dp = self(self, u, v);
twice |= once & dp, once |= dp;
}
auto dp = (once | (bit_ceil(twice + 1u) - 1)) + 1;
order[countr_zero(dp)].push_back(v);
return dp;
};
dfs(dfs, 0, 0);
for (const auto& vec : order | views::reverse)
for (int v : vec) {
f(v);
for (int u : adj[v])
iter_swap(ranges::find(adj[u], v), rbegin(adj[u])),
adj[u].pop_back();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include "../../../kactl/content/number-theory/euclid.h"
// trick to remove const so I can use arbitrary prime mode
// here
#define constexpr ;
#define const ;
#include "../../../library/math/mod_int_pow.hpp"
#undef constexpr
#undef const
int main() {
cin.tie(0)->sync_with_stdio(0);
mint val;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include "../template.hpp"
// trick to remove const so I can use arbitrary prime mode
// here
#define constexpr ;
#define const ;
#include "../../../library/math/mod_int_pow.hpp"
#undef constexpr
#undef const
int main() {
cin.tie(0)->sync_with_stdio(0);
mod = 1'000'000'007;
Expand Down
4 changes: 2 additions & 2 deletions tests/library_checker_aizu_tests/math/count_paths.test.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#define PROBLEM \
"https://judge.yosupo.jp/problem/number_of_increasing_sequences_between_two_sequences"
#include "../template.hpp"
#define constexpr ;
#define const ;
#define mod mod_different_name
#include "../../../library/math/n_choose_k/grow.hpp"
#undef constexpr
#undef const
#undef mod
#define mod mod_not_using
#define modpow modpow_not_using
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include "../template.hpp"
// trick to remove const so I can use arbitrary prime mode
// here
#define constexpr ;
#define const ;
#include "../../../library/math/mod_int.hpp"
#undef constexpr
#undef const
int main() {
cin.tie(0)->sync_with_stdio(0);
int n;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include "../template.hpp"
// trick to remove const so I can use arbitrary prime mode
// here
#define constexpr ;
#define const ;
#include "../../../library/math/mod_int.hpp"
#undef constexpr
#undef const
int main() {
cin.tie(0)->sync_with_stdio(0);
int t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include "../../../library/math/totient.hpp"
// trick to remove const so I can use arbitrary prime mode
// here
#define constexpr ;
#define const ;
#include "../../../library/math/mod_int_pow.hpp"
#undef constexpr
#undef const
int mod_int_tetration(int b, int e, int local_mod) {
if (local_mod == 1) return 0;
if (b == 0) return (e + 1) % 2 % local_mod;
Expand Down
4 changes: 2 additions & 2 deletions tests/library_checker_aizu_tests/math/n_choose_k.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#include "../template.hpp"
// trick to remove const so I can use arbitrary prime mode
// here
#define constexpr ;
#define const ;
#include "../../../library/math/n_choose_k/n_choose_k.hpp"
#undef constexpr
#undef const
int main() {
cin.tie(0)->sync_with_stdio(0);
int num_tests;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#define PROBLEM \
"https://onlinejudge.u-aizu.ac.jp/problems/GRL_5_B"
#include "../template.hpp"
#include "../../../library/trees/shallowest_decomp_tree.hpp"
int main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
vector<vector<int>> adj(n);
map<pair<int, int>, int> weight;
for (int i = 0; i < n - 1; i++) {
int u, v, w;
cin >> u >> v >> w;
weight[{u, v}] = w;
weight[{v, u}] = w;
adj[u].push_back(v);
adj[v].push_back(u);
}
vector<int> res(n);
shallowest(adj, [&](int cent) {
int lowest = 0;
int curr_lowest = 0;
auto dfs = [&](auto&& self, int v, int p,
int height) -> void {
res[v] = max(res[v], height + lowest);
res[cent] = max(res[cent], height);
curr_lowest = max(curr_lowest, height);
for (int u : adj[v])
if (u != p)
self(self, u, v, height + weight[{u, v}]);
};
for (int v : adj[cent]) {
curr_lowest = 0;
dfs(dfs, v, cent, weight[{v, cent}]);
lowest = max(lowest, curr_lowest);
}
lowest = 0;
for (int v : adj[cent] | views::reverse) {
curr_lowest = 0;
dfs(dfs, v, cent, weight[{v, cent}]);
lowest = max(lowest, curr_lowest);
}
});
for (int i = 0; i < n; i++) cout << res[i] << '\n';
}
Loading