Super Pipes and Ant Feeding

No attempts yetTime limit1sMemory limit32 MB

Problem

Bobi gets up every morning and feeds his pet ants. The ants live in a terrarium with a pipe system. The pipe system is a tree with NN nodes, and each pipe is one edge of the tree. The root of the tree is node 1. Because of gravity, liquid flows only from a parent node to its children.

Every pipe has a flow XiX_i, the percentage of the liquid that arrives at the parent node and goes through that pipe to the child node. For example, if 12 liters of liquid arrive at node 1 and two pipes lead out of it, one with flow 30 and one with flow 70, the child behind the first pipe gets 3.6 liters and the child behind the second pipe gets 8.4 liters. The flows of the pipes leaving the same node always add up to 100.

Some of Bobi's pipes are not regular pipes. They are super pipes, and they have the superpower of squaring the amount of liquid that goes through them. In the example above, if the pipe with flow 30 is a super pipe and its superpower is on, that child gets 3.62=12.963.6^2 = 12.96 liters while the other child still gets 8.4 liters. More liquid then leaves the node than entered it. That is exactly why they are called super pipes.

Bobi can turn the superpower of each super pipe on or off. A super pipe with its superpower off behaves like a regular pipe.

The ants live only in the nodes without children, the leaves. To feed all the ants in leaf ii, that leaf must receive at least KiK_i liters. Bobi feeds the ants by pouring LL liters of liquid into the root. He does not have much money, so he wants to buy as little liquid as possible. Find the smallest LL for which every leaf receives the amount it needs.

In the given data the answer LL never exceeds 21092 \cdot 10^9.

Input

The first line contains the integer NN, the number of nodes (1N10001 \le N \le 1000).

Each of the next N1N - 1 lines contains four integers AiA_i, BiB_i, XiX_i, TiT_i (1Ai,BiN1 \le A_i, B_i \le N, 1Xi1001 \le X_i \le 100, 0Ti10 \le T_i \le 1). AiA_i and BiB_i are the two nodes joined by a pipe, XiX_i is the flow of that pipe, and TiT_i says whether the pipe is a super pipe. If TiT_i is 1 the pipe is a super pipe, and if TiT_i is 0 it is a regular pipe. Liquid flows away from node 1, so the endpoint closer to node 1 is the parent. The N1N - 1 pipes form a tree.

The last line contains NN integers KiK_i. If node ii is a leaf, KiK_i is an integer between 1 and 10. Otherwise KiK_i is 1-1.

Output

Print the smallest amount of liquid Bobi has to pour into the root, rounded to three decimal places, on one line. Always write three digits after the decimal point. For example, if the answer is exactly 8, print 8.000.