The doctor is lost in the park and the engineer is searching the park to find her. We…
- User
The doctor is lost in the park and the engineer is searching the park to find her. We know that in the park n There are n intersections with n
1 n−1 intersections are connected, so that any intersection can be reached from any intersection. (The graph of the park roads is in the form of a tree) Mrs. Doctor at the intersection e e is sitting and Mr. Engineer who is at the intersection s s is located, wants to find him.
Mr. Engineer, who has come to this park for the first time and does not know it anywhere, chooses one of the crossings connected to it at random and with equal probability at every intersection and goes through it. Passing each passage also takes a certain amount of time. He does this as much as the intersection e e arrives and finds the doctor.
Write a program that captures different location scenarios s s and e e, the mathematical expectation of the time it takes for Mr. Engineer to find Ms. Doctor.
input The first line of input contains two natural numbers n n, the number of intersections and q q is the number of scenarios.
in each of n
1 n−1 next line, three natural numbers u u and v v and t t is said to mean the existence of a passage between two intersections u u and v v is that t It takes t minutes to cross it.
Then in each of q q The next line is two numbers s s, the starting place of the movement of Mr. Engineer and e e, the intersection where the doctor is sitting has come.
1 ≤ n , q ≤ 100
000 1 ≤ n, q ≤ 100 000
( u ≠ v ) (u (v) 1 ≤ u , v ≤ n 1≤u,v≤n
1 ≤ t ≤ 1
000 1≤t≤1 000
1 ≤ s , e ≤ n 1 ≤ s, e ≤ n
output in q q Output line In each of its lines, for one scenario, print the mathematical expectation of the time it takes for Mr. Engineer to find Ms. Doctor. If the relative error of your answer and your original answer is less than 1 0
7 10 -7 Yes, your answer will be accepted.
sub-issues Constraint score subproblem 1 10 n ≤ 10 n≤10 220 n ≤ 1
000 n≤1 000 3 70 without additional restrictions Example Sample entry 1 3 3 1 2 10 2 3 20 1 2 2 3 1 3 Plain text Sample output 1 10,000 40,000 50,000 Plain text Sample input 2 4 2 1 2 10 1 3 20 1 4 30 1 2 3 4 Plain text Sample output 2 110,000 110,000 c++
- Assistant