#P1351. [NOIP 2014 提高组] 联合权值
[NOIP 2014 提高组] 联合权值
Description
An undirected connected graph has vertices and edges. The vertices are numbered from to , and the weight of vertex is . Each edge has length . For any two vertices and , their distance is defined as the length of the shortest path from to . For a pair of vertices in , if their distance is , then they generate a joint weight of .
Among all ordered pairs in that can generate a joint weight, what is the maximum joint weight? What is the sum of all joint weights?
Input Format
The first line contains integer .
The next lines each contain positive integers separated by a space, indicating that there is an edge between vertex and vertex .
The last line contains positive integers separated by single spaces, where the -th integer indicates that the weight of vertex in is .
Output Format
Output a single line containing integers separated by a space: the maximum joint weight on graph and the sum of all joint weights. Since the sum may be large, output it modulo .
5
1 2
2 3
3 4
4 5
1 5 2 3 10
20 74
Hint
Sample Explanation.

For the input in this example, the graph is as shown above. The ordered pairs at distance are .
Their joint weights are . The maximum is , and the total sum is .
Constraints
- For of the testdata, .
- For of the testdata, .
- For of the testdata, , .
It is guaranteed that there exists at least one ordered pair that can generate a joint weight.
Translated by ChatGPT 5
京公网安备 11011102002149号