Skip to content

Instantly share code, notes, and snippets.

@potetisensei
Last active February 6, 2019 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save potetisensei/2e95637586b5bb181112b6d922283ff1 to your computer and use it in GitHub Desktop.
Save potetisensei/2e95637586b5bb181112b6d922283ff1 to your computer and use it in GitHub Desktop.
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