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

An Interesting Tree Problem

Правка en1, от Pranshu_Pandya, 2023-10-07 19:24:53

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 was 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.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский Pranshu_Pandya 2023-10-07 19:26:41 3 Tiny change: 'ng. But I was not able ' -> 'ng. But I am not able ' (published)
en1 Английский Pranshu_Pandya 2023-10-07 19:24:53 1171 Initial revision (saved to drafts)