GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Friday, 10 June 2022

[Solution] Full Path Eraser CodeChef Solution | CodeChef Problem Solution 2022

There is a rooted tree of N vertices rooted at vertex 1. Each vertex v has a value Av associated with it.

You choose a vertex v (possibly the root) from the tree and remove all vertices on the path from the root to the vertex v, also including v. This will result in a forest of zero or more connected components.

The beauty of a connected component is the GCD 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 v.

    Solution Click Below:-  CLICK HERE


    Here, GCD stands for Greatest Common Divisor.

    Input Format

    • The first line contains a single integer T — the number of test cases. Then the test cases follow.
    • The first line of each test case contains an integer N — the size of the tree.
    • The second line of each test case contains N space-separated integers A1,A2,,AN denoting


    •  the values associated with each vertex.
    • The next N1 lines contain two space-separated integers u and v — denoting an undirected edge between nodes u and v.

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

    Constraints

    • 1T2104
    • 1N3105

    No comments:

    Post a Comment