Hypno
Time limit2sMemory limit512 MB
Find the minimum expected time to walk from intersection 1 to intersection n when each road may put you to sleep with a Hypno you are susceptible to, and you learn each road's result after trying it.
- Level
Hard9 of 10
- Topics
- Graph, Shortest path, Probability
- Solved
- No attempts yet
Statement
You have just heard that a new PokéStop has opened somewhere in your city. You want to go there and collect the items it offers. The city has intersections connected by bidirectional roads, numbered from 1 to . You are at intersection 1, and the PokéStop is at intersection . Crossing any road takes one minute.
Each road has a single Hypno. When you reach the midpoint of a road, the Hypno uses its psychic power on you, and you fall into a very short sleep. The Hypno then makes you sleepwalk to a random endpoint of that road. After one minute, you are at the opposite end with probability , or back at the same intersection otherwise.
You are immune to each individual Hypno with probability . If the road you are on has a Hypno you are immune to, you always cross the road safely in one minute. If it has a Hypno you are susceptible to, you fall asleep on every crossing of that road. You do not know initially which roads have which Hypno, but after you attempt to cross a road, you know which endpoint you are currently at. What is the minimum expected time to reach the PokéStop at intersection ?
Input
The first line contains two integers and (, ), the number of intersections and the number of roads. Each of the next lines contains two integers and (, ), the intersections connected by a road. No two intersections are connected by more than one road. The city is connected, so you can reach every intersection from every other intersection.
Output
Print a single real number, the minimum expected time to reach intersection . Your answer is correct if its absolute or relative error does not exceed .
Hint
In the first sample, the optimal strategy is to repeatedly try to go directly to the destination using the second road. With probability , you are immune to the Hypno on that road and reach the destination in 1 minute. Otherwise, you are susceptible, and the expected time in that case is . The overall expected time is .
In the second sample, repeatedly trying the second intersection takes 3 minutes in expectation. Trying only the third intersection also takes 3 minutes. A better strategy exists.
