A tree is a graph where each node is connected to each other, and there is exactly one path between any two nodes. One day, Jessica gives Roger a tree, with the
1 x y
: Find the mean of all the values of the nodes on the path fromx
toy
, rounded to the nearest integer.2 x y
: Find the median of all the values of the nodes on the path fromx
toy
, rounded to the nearest integer.3 x y
: Find the mode of all the values of the nodes on the path fromx
toy
. In the case of a tie, print the smallest value.
Note: The rules of rounding are as follows: if the decimal part of the number is less than
For example,
Constraints
Input Specification
The first line of input will contain two integers,
The second line of input will contain
The next
The next
Output Specification
Sample Input
4 4
1 2 3 3
1 2
2 3
3 4
1 1 4
2 2 4
3 1 4
3 1 2
Sample Output
2
3
3
1
Explanation for Sample Output
For the first query, we pass through all
For the second query, we pass through the nodes of weight
For the third query, we pass through all
For the last query, we pass through the first two nodes with weight
Comments
This comment is hidden due to too much negative feedback. Show it anyway.
That's still less than 4.5, so it rounds down.