Gopher Residence
시간 제한3초메모리 제한2048 MB
방들이 1번 방을 뿌리로 하는 트리를 이루고, 각 고퍼는 확률 1/2로 남으며, 이후 부분 트리 용량을 지키며 무작위로 방을 채운다. 최종 생존 수의 기댓값을 구한다.
문제
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 rooms, the th either has a unique room above it, or is the exit room . When a gopher living in room i exits the residence, the must travel up to room , and then to the room above and so on, until they reach room and exit the residence.
Each room has gophers who wish to live in the room. Each room also has a “travel capacity” , which upper bounds the number of gophers that may live under (and including) room . All gophers leave the residence at exactly o’clock each morning, so if there are more than gophers living under (and thus travelling through) room , there will be a traffic jam.
You know that probably not all of the gophers who say they wish to live in room will actually want to. In fact, each gopher will independently flip a coin and decide with probability 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 that there are more than gophers that want to live in a room under (or including) room . 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 , the number of rooms in the residence (). The following lines each contain two integers and , indicating that is the room directly above (). It is guaranteed that every room except room has a room directly above it.
The final lines each contain two integers , , indicating that there are gophers living in the th room, and the capacity of the th room is ().
출력
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 .