atcoder#ARC115F. [ARC115F] Migration
[ARC115F] Migration
Score : points
Problem Statement
Given is a tree with vertices numbered . The -th edge connects Vertex and Vertex . Additionally, Vertex has an integer written on it. We have pieces, the -th of which is initially on Vertex . You will repeat the following operation: choose a piece and move it to one of the vertices adjacent to the vertex the piece is currently on. You will end this process when each piece is on Vertex . It is not required for each piece to go along the shortest path from Vertex to Vertex . For an arrangement of the pieces, let its potential be the sum of the integers written on the vertices the pieces are on. If multiple pieces are on the same vertex, the integer on that vertex is added the number of times equal to that number of pieces. Find the minimum possible value of the maximum potential during the process, including the initial and final states.
Constraints
- The given graph is a tree.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
3
1 3 2
1 2
2 3
2
1 3
3 1
4
We can make the maximum potential during the process, as follows:
- Initially, the potential is .
- Move Piece to Vertex . The potential is now .
- Move Piece to Vertex . The potential is now .
- Move Piece to Vertex . The potential is now .
- Move Piece to Vertex . The potential is now .
There is no way to make the maximum potential during the process less than , so the answer is .
7
100 101 1 100 101 1 1000
1 2
2 3
4 5
5 6
1 7
4 7
2
1 3
4 6
201
5
2 1 100 5 6
1 2
2 3
3 4
3 5
2
2 2
4 5
101
4
1 2 3 100
1 4
2 4
3 4
9
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
115
6
1 100 1 1 10 1000
1 2
2 3
4 5
1 6
4 6
3
1 3
5 5
5 5
102