What is the chain tree split
Chain split tree, computer terminology, refers to a partitioning of an algorithm tree, which tree to split into a plurality of side chains by weight, to ensure that each point belongs and only belongs to one strand, and then the data structure ( Fenwick tree, \ (BST \) , \ (SPLAY \) , segment tree, etc.) to maintain each strand. --Baidu Encyclopedia
Tree maintenance is split light chain, heavy chain, and other data structures maintained. (Generally Fenwick tree or tree line)
concept
Heavy Son: all sons siz maximum junction
Light Son: In addition to heavy son's son
(emphasize: a node point other than the son of the weight is lighter son)
Heavy side: even as his son and heavy side
Light side: the light side even as his son
Heavy chain: the path formed by connecting a plurality of multiple edges
Light chain: a path formed by connecting a plurality of side light (usually only one)
Set of variables
\ (FA [X] \) , \ (X \) father
\ (DEP [X] \) , \ (X \) depth
\ (SIZ [X] \) , \ (X \) subtree size
\ (son [the X-] \) , \ (the X-\) heavy son
\ (DFN [the X-] \) , \ (the X-\) of new number (do (dfs \) \ order)
\ (Top [the X- ] \) , \ (the X-\) the top node where the heavy chain
(emphasize: we can guarantee that each node in a heavy chain only in years)
\ (RK [the X-] \) , \ (DFN [] \ ) of \ (X \) is the node in the tree
step
Usually twice \ (the DFS \) .
The first pass: find \ (fa [], dep [ ], siz [], son [] \)
void dfs(int x)
{
dep[x] = dep[fa[x]] + 1, siz[x] = 1;
for (int p = tail[x], v; p; p = e[p].fr)
{
v = e[p].v; fa[v] = x;
dfs(v), siz[x] += siz[v];
if (siz[v] > siz[son[x]]) son[x] = v;
}
}
The second time: find \ (dfn [], top [ ], rk [] \)
void dfs1(int x, int fat)
{
dfn[x] = ++tot; rk[tot] = x; top[x] = fat;
if (! son[x]) return;
dfs1(son[x], fat);
for (int p = tail[x], v; p; p = e[p].fr)
{
v = e[p].v;
if (v == son[x]) continue;
dfs1(v, v);
}
}
The reason we first \ (dfs \) heavy son, because we want to ensure that each node on a heavy chain \ (dfn [] \) is continuous.
This allows us to maintain data structure.
Sometimes you can not find \ (RK [] \) .
time complexity
It can be shown as O (nlog ^ 2n)
example:
[ZJOI2008] tree statistics
[NOI2015] package manager
[SDOI2011] staining
[SHOI2012] magic tree
[HAOI2015] tree operation
[HEOI2016 / TJOI2016] tree