Little Bobi gets up every morning and feeds his favourite pets: ants. He keeps them in a terrarium with a pipe system that can be represented as a tree with
We know the flow
Node 1 from the image has 12 liters of liquid in it and has two pipes after it. One has the flow of
Some of Bobi's pipes aren't just regular pipes; they are a bit strange. They are super pipes that have the superpower to square the amount of liquid flowing through them. In the previous example, if the first pipe has the superpower, node 2 gets 12.96 liters and node 3 still gets only 8.4 liters. Notice now that a node has more liquid leaving it than the amount entering it. This is exactly the reason why these pipes are super pipes!
All super pipes can have their superpower turned on or off by Bobi.
The ants live only in the leaves of the tree (nodes that don't have any children). For each leaf, we know the required amount of liquid
Please note: The input data is such that the required number
Input
The first line of input contains the integer
Each of the following
The following line contains
Output
The first and only line of output must contain the required number from the task.
Please note: The allowed absolute error from the correct (precise) solution is
Sample Input 1
5
1 2 50 0
1 3 50 0
2 4 25 0
2 5 75 1
-1 -1 4 1 9
Sample Output 1
8.00
Explanation for Sample Output 1
If Bobi pours 8 liters of liquid into the root of the tree, node 3 will get 4 liters, node 4 will get 1 liter and node 5 will get 9 liters. These nodes are leaves (they have ants in them) and this is the exact minimum amount the ants need to get. Also, 8 liters is the minimum amount of liquid that satisfies the "ant" conditions.
Sample Input 2
3
1 2 20 1
1 3 80 1
-1 4 8
Sample Output 2
10.0000
Sample Input 3
6
1 2 100 1
2 3 20 0
2 4 20 0
2 5 60 0
4 6 100 1
-1 -1 1 -1 1 2
Sample Output 3
2.659
Comments