[Solution] Full Path Eraser CodeChef Solution | CodeChef Problem Solution 2022
There is a rooted tree of vertices rooted at vertex . Each vertex has a value associated with it.
You choose a vertex (possibly the root) from the tree and remove all vertices on the path from the root to the vertex , also including . This will result in a forest of zero or more connected components.
The beauty of a connected component is the of the values of all vertices in the component. Find the maximum value of the sum of beauties of the obtained connected components for any choice of .
Here, stands for Greatest Common Divisor.
Input Format
- The first line contains a single integer — the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer — the size of the tree.
- The second line of each test case contains space-separated integers denoting the values associated with each vertex.
- The next lines contain two space-separated integers and — denoting an undirected edge between nodes and .
It is guaranteed that the edges given in the input form a tree.
Output Format
For each test case output the maximum value of the sum of beauties of the obtained connected components for any choice of .
No comments:
Post a Comment