Skip to content

Instantly share code, notes, and snippets.

@potetisensei
Last active Feb 6, 2019
Embed
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 = e.to;
if (u == p) continue;
if (sz[u] != mx[v]) continue;
l = e.len;
break;
}
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