There is an undirected tree T of size n, with edges of length 1. Initially, each of the nodes(1-indexed) 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.↵
Constraints: n<=1e5.↵
Seen this in some recent oa and tried alot but not able to solve. Can anyone help please?
↵
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.↵
Constraints: n<=1e5.↵
Seen this in some recent oa and tried alot but not able to solve. Can anyone help please?