#P6287. [COCI 2016/2017 #1] Mag
[COCI 2016/2017 #1] Mag
Description
You will be given a tree connected by undirected edges. Each node in the tree has a magic value.
We define the magic value of a path as the product of the magic values of all nodes on the path divided by the number of nodes on the path.
For example, if a path contains two nodes with magic values , then the magic value of this path is .
Please compute the magic value of the path with the smallest magic value in this tree.
Input Format
The first line contains an integer , indicating that the tree has nodes, numbered .
The next lines each contain two integers , indicating that nodes and are connected by an undirected edge.
The next lines each contain an integer , indicating the magic value of node .
Output Format
Print one line containing a reduced fraction .
2
1 2
3
4
3/1
5
1 2
2 4
1 3
5 2
2
1
1
1
3
1/2
Hint
Sample Explanation
Sample 1 Explanation
Note that a path may contain only one node.
In this tree, the path with the smallest magic value contains node , and its magic value is .
Sample 2 Explanation
In this tree, the path with the smallest magic value contains nodes , and its magic value is .
Constraints
For of the testdata, , , .
It is guaranteed that will not exceed .
Notes
This problem is translated from COCI2016-2017 CONTEST #1 T4 Mag.
Translated by ChatGPT 5
京公网安备 11011102002149号