#P4745. [CERC2017] Gambling Guide

[CERC2017] Gambling Guide

题目描述

A railroad network in a nearby country consists of nn cities numbered 11 through nn, and mm two-way railroad tracks each connecting two different cities. Tickets can only be purchased at automated machines installed at every city. Unfortunately, hackers have tampered with the ticket machines and now they all work as follows: when a single coin is inserted in the machine installed at city aa, the machine dispenses a single one-way ticket from aa to a random neighboring city. More precisely, the destination city is chosen uniformly at random among all cities directly connected to a with a railroad track. Destinations on different tickets originating in the same city are independent.

A computer science student needs to travel from city 11 (where she lives) to city nn (where a regional programming contest has already started). She knows how the machines work (but of course cannot predict the random choices) and has a map of the railway network. In each city, when she purchases a ticket, she can either immediately use it and travel to the destination city on the ticket, or discard the ticket and purchase a new one. She can keep purchasing tickets indefinitely. The trip is finished as soon as she reaches city nn.

After doing some calculations, she has devised a traveling strategy with the following properties:

  • The probability that the trip will eventually finish is 11.
  • The expected number of coins spent on the trip is the smallest possible.

Find the expected number of coins she will spend on the trip.

输入格式

The first line contains two integers nn and m(1n,m300000)m(1 \le n,m \le 300 000) — the number of cities and the number of railroad tracks. Each of the following mm lines contains two different integers aa and b(1a,bn)b(1 \le a, b \le n) which describe a railroad track connecting cities aa and bb.

There will be at most one railroad track between each pair of cities. It will be possible to reach city nn starting from city 11.

输出格式

Output a single number — the expected number of coins spent. The solution will be accepted if the absolute or the relative difference from the judges solution is less than 10610^{-6}.

4 4
1 2
1 3
2 4
3 4
3.0000000000
5 8
1 2
1 3
1 4
2 3
2 4
3 5
5 4
2 5
4.1111111111