Gambling Guide
Time limit3sMemory limit512 MB
On an undirected graph, find the minimum expected number of random tickets (with rejection allowed) needed to travel from city 1 to city n.
- Level
Hard8 of 10
- Topics
- Graph, Probability, Greedy, Math
- Solved
- No attempts yet
Problem
A railroad network in a nearby country has cities numbered 1 to and two-way tracks, each of which joins two different cities. Tickets are sold only by the automated machines installed in every city. Hackers tampered with those machines, so every one of them now works like this: when a single coin is inserted into the machine in city , the machine prints one one-way ticket from to a neighbouring city, chosen uniformly at random among all cities joined to by a track. Destinations of different tickets bought in the same city are independent.
A computer science student has to travel from city 1, where she lives, to city , where a regional programming contest has already started. She knows how the machines work, though she cannot predict the random choices, and she has a map of the railroad network. After buying a ticket she reads the destination printed on it, and she can either use the ticket at once and travel to that city, or throw the ticket away and buy a new one in the city she is standing in. She can keep buying tickets forever. The trip ends the moment she reaches city .
After some calculation she found a travel strategy with these two properties:
- The probability that the trip eventually ends is .
- The expected number of coins spent on the trip is as small as possible.
Find the expected number of coins she will spend.
Input
The first line contains two integers and (), the number of cities and the number of railroad tracks.
Each of the next lines contains two different integers and (), describing a track that joins city and city . Each pair of cities is joined by at most one track. City is reachable from city 1.
Output
Print the expected number of coins, rounded to exactly digits after the decimal point, on one line.
Hint
The figure shows the railroad network of the second example.
