Today I'm going to present an interesting tree task from the CSES Problem Set which is using a technique that's often overlooked, which is what I call the two dfs technique or as it's also called, rerooting DP (although this is an easier example of this technique).
Problem: https://cses.fi/problemset/task/1133
Solution Code: https://cses.fi/paste/b05278e7c649ddb07b8553/
Another rerooting tutorial: https://usaco.guide/gold/all-roots?lang=cpp
My website: https://stefdasca.ro/
Codeforces profile: https://codeforces.com/profile/stefdasca
Discord server: https://discord.gg/ZDfmQBKHkC
Facebook page: https://www.facebook.com/stefan.dascalescu.2013/
Linkedin: https://www.linkedin.com/in/stefdasca/
Instagram page: https://www.instagram.com/stefdasca/