File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55// ! https://youtu.be/wDwaMo5xa-k
66// ! @code
77// ! vector<basic_string<int>> g(n);
8- // ! edge_cd(g, [&](int cent , int m) {
9- // ! // subtrees of [0, m) of g[cent ]: 1st edge-set
10- // ! // subtrees of [m, sz(g[cent ])): 2nd edge-set
8+ // ! edge_cd(g, [&](int c , int m) {
9+ // ! // subtrees of [0, m) of g[c ]: 1st edge-set
10+ // ! // subtrees of [m, sz(g[c ])): 2nd edge-set
1111// ! });
1212// ! @endcode
1313// ! handle single-edge-paths separately
1414// ! @time O(n logφ n)
1515// ! @space O(n)
1616template <class G > void edge_cd (vector<G>& g, auto f) {
17- vi siz (sz (g));
17+ vi s (sz (g));
1818 auto ctd = [&](auto ctd, int u, int p, int m) -> int {
19- siz [u] = 1 ;
19+ s [u] = 1 ;
2020 for (int v : g[u])
2121 if (v != p) {
2222 if (int c = ctd (ctd, v, u, m); c != -1 ) return c;
23- siz [u] += siz [v];
23+ s [u] += s [v];
2424 }
25- return 2 * siz[u] > m ? siz[p] = m + 1 - siz[u],
26- u : -1 ;
25+ return 2 * s[u] > m ? s[p] = m + 1 - s[u], u : -1 ;
2726 };
2827 auto dfs = [&](auto dfs, int u, int m) {
2928 if (m < 2 ) return ;
3029 u = ctd (ctd, u, u, m);
3130 int sum = 0 ;
3231 auto it = partition (all (g[u]), [&](int v) {
33- ll x = sum + siz [v];
32+ ll x = sum + s [v];
3433 return x * x < m * (m - x) ? sum = x : 0 ;
3534 });
3635 f (u, it - begin (g[u]));
You can’t perform that action at this time.
0 commit comments