Last active
February 6, 2019 15:25
-
-
Save potetisensei/2e95637586b5bb181112b6d922283ff1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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