|
9 | 9 |
|
10 | 10 | // CUT begin |
11 | 11 | // Heavy-Light Decomposition of trees |
12 | | -// Based on <http://beet-aizu.hatenablog.com/entry/2017/12/12/235950> |
| 12 | +// Based on http://beet-aizu.hatenablog.com/entry/2017/12/12/235950 |
13 | 13 | struct HeavyLightDecomposition { |
14 | 14 | int V; |
15 | 15 | int k; |
16 | 16 | int nb_heavy_path; |
17 | 17 | std::vector<std::vector<int>> e; |
18 | | - std::vector<int> par; // par[i] = parent of vertex i (Default: -1) |
19 | | - std::vector<int> depth; // depth[i] = distance between root and vertex i |
20 | | - std::vector<int> subtree_sz; // subtree_sz[i] = size of subtree whose root is i |
21 | | - std::vector<int> heavy_child; // heavy_child[i] = child of vertex i on heavy path (Default: -1) |
22 | | - std::vector<int> tree_id; // tree_id[i] = id of tree vertex i belongs to |
| 18 | + std::vector<int> par; // par[i] = parent of vertex i (Default: -1) |
| 19 | + std::vector<int> depth; // depth[i] = distance between root and vertex i |
| 20 | + std::vector<int> subtree_sz; // subtree_sz[i] = size of subtree whose root is i |
| 21 | + std::vector<int> heavy_child; // heavy_child[i] = child of vertex i on heavy path (Default: -1) |
| 22 | + std::vector<int> tree_id; // tree_id[i] = id of tree vertex i belongs to |
23 | 23 | std::vector<int> aligned_id, aligned_id_inv; // aligned_id[i] = aligned id for vertex i (consecutive on heavy edges) |
24 | | - std::vector<int> head; // head[i] = id of vertex on heavy path of vertex i, nearest to root |
25 | | - std::vector<int> head_ids; // consist of head vertex id's |
26 | | - std::vector<int> heavy_path_id; // heavy_path_id[i] = heavy_path_id for vertex [i] |
| 24 | + std::vector<int> head; // head[i] = id of vertex on heavy path of vertex i, nearest to root |
| 25 | + std::vector<int> head_ids; // consist of head vertex id's |
| 26 | + std::vector<int> heavy_path_id; // heavy_path_id[i] = heavy_path_id for vertex [i] |
27 | 27 |
|
28 | | - HeavyLightDecomposition(int sz = 0) : V(sz), k(0), nb_heavy_path(0), e(sz), par(sz), depth(sz), subtree_sz(sz), heavy_child(sz), tree_id(sz, -1), aligned_id(sz), aligned_id_inv(sz), head(sz), heavy_path_id(sz, -1) {} |
| 28 | + HeavyLightDecomposition(int sz = 0) |
| 29 | + : V(sz), k(0), nb_heavy_path(0), e(sz), par(sz), depth(sz), subtree_sz(sz), heavy_child(sz), tree_id(sz, -1), aligned_id(sz), aligned_id_inv(sz), head(sz), heavy_path_id(sz, -1) {} |
29 | 30 | void add_edge(int u, int v) { |
30 | 31 | e[u].emplace_back(v); |
31 | 32 | e[v].emplace_back(u); |
|
0 commit comments