Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

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

Автор Pranshu_Pandya, история, 12 месяцев назад, По-английски

Hello everyone!

I recently come across an interesting tree problem.

There is an undirected tree, T, with edges of length 1. Initially, each of the nodes stores a value equal to the node number. Shuffle these values among the nodes in such a way that no node stores a value equal to its node number. There are two values to determine:

1) The minimum possible sum of the distances between the initial and final positions of all values.

2) The maximum possible sum of the distances between the initial and final positions of all values.

1<=number of nodes<=1e5.

I was able to solve the case of minimum possible sum by applying maximum matching. But I am not able to come up with an efficient solution for 2nd case. I am also struggling to prove its correctness for the n^2 solution(my intution is repatedly finding diameter and swapping the node at diameter and removing them after adding their distances). I discussed the probelm with many of my friends(some are CMs) but we are not able to come up with efficient algo for second case.

It would be great if someone can help in solving the second case.

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

»
12 месяцев назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Someone just asked about the same problem here on CF a week or two ago.

The problem is the same as BOI 2020 Village (Minimum) and BOI 2020 Village (Maximum).

You can read the tutorial here.