Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- auto dfs = [&](ll u, ll parent, auto&& self) -> ll {
- ll mx1 = 0, mx2 = 0;
- for (auto v : adj[u]) {
- if (v != parent) {
- ll tmp = self(v, u, self); // Use self for recursion
- if (tmp > mx1) {
- mx2 = mx1;
- mx1 = tmp;
- } else if (tmp > mx2) {
- mx2 = tmp;
- }
- }
- }
- res = max(res, mx1 + mx2 + val[u]);
- return max(mx1, mx2) + val[u];
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement