Groups
Category
The Z-function of a string S computes for each position i the length of the longest substring starting at i that matches the prefix of S.
Rerooting (a.k.a. 换根 DP) computes a per-node answer as if each node were the root, in total O(n) time on trees.