Reimu's Teleportation Practice
Time limit6sMemory limit1024 MB
Given a tree where K nodes are priests who can teleport to any priest with equal chance, find the minimum expected moves from A to B.
- Level
Hard8 of 10
- Topics
- Tree, Dynamic programming, Probability
- Solved
- No attempts yet
Problem
In Reimu's world of Gensokyo, there are gentlemen. Among them, are Myojin priests who serve the deity Myojin. Two gentlemen are connected by bidirectional roads, and any two gentlemen can reach each other using one or more roads. Over days, Reimu decides to practice her ability, teleportation. On day , she starts at gentleman and wants to reach gentleman , where Marisa is. Reimu moves between gentlemen using the following actions.
- Pick one of the gentlemen directly connected to the current one by a road and move there.
- If the current gentleman is a Myojin priest, teleport to one of the Myojin priests, including the current one, chosen with equal probability.
Marisa wants Reimu to finish her practice quickly so they can play, so she wants to tell Reimu which actions to use in what order. At every step, Reimu chooses the action that minimizes the expected number of actions needed to reach . Print the expected number of actions to go from to .
Input
The first line contains , , and separated by spaces. (; ; ) Each of the next lines contains and , meaning gentleman and gentleman are connected by a road. () It is guaranteed that any two gentlemen can reach each other using one or more roads. The next line contains the numbers of the Myojin priests . () Each of the next lines contains and , meaning on day Reimu goes from gentleman to gentleman . (; )
Output
Print lines. On line , print the expected number of actions to go from to . Your answer must have a relative error of at most against the correct answer.