Skip to content

Instantly share code, notes, and snippets.

Last active Feb 6, 2019
What would you like to do?
LL dfs(int v, int p, int k) {
int rem = k - 2*(sz[v]-mx[v]);
if (rem <= 0) return 0;
LL ret = INF;
int u;
LL l;
for (auto &e : es[v]) {
u =;
if (u == p) continue;
if (sz[u] != mx[v]) continue;
l = e.len;
return dfs(u, v, rem) + l * rem;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment