Блог пользователя infinitepro

Автор infinitepro, история, 4 года назад, По-английски

The title states the problem — source. Constraints $$$N \le 25e4$$$

  • Проголосовать: нравится
  • +20
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится -9 Проголосовать: не нравится

Downvoters care to explain whats wrong?

»
4 года назад, # |
  Проголосовать: нравится +11 Проголосовать: не нравится

Looks like a copy of this problem. The solution is to work with the centroid of the tree. All edges must go either towards the centroid or away from the centroid. In other words, there is an optimal solution where for any arbitrary node $$$u$$$ and centroid $$$c$$$, it is possible to reach $$$u$$$ from $$$c$$$ or $$$c$$$ from $$$u$$$. So the solution boils down to doing a knapsack problem on the subtree sizes of the tree rooted at the centroid.

Don't ask me for the proof, because I do not know it :3, I only know the solution because it is a very popular problem of POI.