Gopher Residence

시간 제한3초메모리 제한2048 MB

요약
방들이 1번 방을 뿌리로 하는 트리를 이루고, 각 고퍼는 확률 1/2로 남으며, 이후 부분 트리 용량을 지키며 무작위로 방을 채운다. 최종 생존 수의 기댓값을 구한다.
난이도

어려움10점 중 8점

유형
트리, 확률, 동적 계획법, DFS
정답자
아직 제출이 없습니다

문제

The Edmonton gopher population has expanded rapidly over the past few years. To accommodate this increased number of gophers, the city has built a vast gopher residence under the legislature building. The residence consists of NN rooms, the iith either has a unique room p_ip\_i above it, or is the exit room i=1i=1. When a gopher living in room i exits the residence, the must travel up to room p_ip\_i, and then to the room above p_ip\_i and so on, until they reach room 11 and exit the residence.

Each room ii has x_ix\_i gophers who wish to live in the room. Each room also has a “travel capacity” c_ic\_i, which upper bounds the number of gophers that may live under (and including) room ii. All gophers leave the residence at exactly 99 o’clock each morning, so if there are more than c_ic\_i gophers living under (and thus travelling through) room ii, there will be a traffic jam.

You know that probably not all of the x_ix\_i gophers who say they wish to live in room ii will actually want to. In fact, each gopher will independently flip a coin and decide with probability 12\frac{1}{2} whether they actually wish to live in the residence.

The problem is that after all gophers have determined if they actually want to live in the residence, it may not be possible to accommodate them all. That is, it may still be that for some rooms ii that there are more than c_ic\_i gophers that want to live in a room under (or including) room ii. So the city will hold a lottery to determine which of these gophers actually get to live in the residence by repeating the following process: while some gopher that wants to live in the residence can be included without violating any capacities, pick one of them at random and add them to the residence.

The city is unsure of how many gophers will actually end up living in the residence and have asked you to calculate the expected number of gophers that will live there, subject to the above process.

입력

The first line of input contains one integer NN, the number of rooms in the residence (1≤N≤1001≤N≤100). The following N−1N-1 lines each contain two integers uu and vv, indicating that uu is the room directly above vv (1≤u\<v≤N1≤u\<v≤N). It is guaranteed that every room except room 11 has a room directly above it.

The final NN lines each contain two integers x_ix\_i, c_ic\_i, indicating that there are x_ix\_i gophers living in the iith room, and the capacity of the iith room is c_ic\_i (0≤x_i,c_i≤1000≤x\_i,c\_i≤100).

출력

Output the expected number of gophers living in the residence as a real number. Your answer will be considered correct as long as the relative or absolute error is at most 10−610^{-6}.

예제3

  1. 예제 1

    입력
    1
    5 3
    
    예상 출력
    2.28125000000000000000
    
  2. 예제 2

    입력
    4
    1 2
    2 3
    3 4
    2 1
    2 1
    1 1
    1 1
    
    예상 출력
    0.98437500000000000000
    
  3. 예제 3

    입력
    4
    1 2
    2 3
    2 4
    0 5
    0 4
    5 3
    5 3
    
    예상 출력
    3.75000000000000000000