Disease
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

Gates is a super rich man . Because of the influence of COVID-19 , he had to do enough protection .

To keep himself away from the virus , he formulated strict protective measures .

Gates has exactly n-1 servants , he numbers them 2 to n (Gates is number 1) , and n-1 edges (u,v,a,b) satisfies that u and v may contact with each other , if one of them is infected with the virus , then the other one has probability of being infected .

We promise that the n-1 edges from a tree , Gates is the root .

The level of a person is defined as the depth of him on the tree (Gates's level is always 1) .

Now we know for the i-th person , he has probability of infecting the virus from the outside world (At the beginning) .

We define the disaster value as the lowest level of the person who infected of the virus . ( If there are no one infected , the disaster value is 0 ) .

Now please help Gates to calculate what's the expectation of the disaster value ?

输入描述:

The first line has an integer  .

The next n lines contains n pair of integers , the i-th pair describes .

Then n-1 lines , each line contains 4 integers u,v,a,b described before .

输出描述:

If the answer is  (simplest fraction),print  .
示例1

输入

复制
3
0 1
0 1
1 1
1 2 1 2
2 3 1 2

输出

复制
250000004

说明

The probability of infection (1,2,3) is \frac {1}{4} .

The probability of infection (2,3) is \frac {1}{4} .

The probability of infection (3) is \frac {1}{2} .

So the answer is \frac{1}{4}\times 1+\frac{1}{4}\times 2+\frac{1}{2}\times 3=\frac{9}{4} .