#ABC144F. Fork in the Road

Fork in the Road

题目描述

There is a cave consisting of NN rooms and MM one-directional passages. The rooms are numbered 11 through NN.

Takahashi is now in Room 11, and Room NN has the exit. The ii-th passage connects Room sis_i and Room tit_i (sis_i < tit_i) and can only be traversed in the direction from Room sis_i to Room tit_i. It is known that, for each room except Room NN, there is at least one passage going from that room.

Takahashi will escape from the cave. Each time he reaches a room (assume that he has reached Room 11 at the beginning), he will choose a passage uniformly at random from the ones going from that room and take that passage.

Aoki, a friend of Takahashi's, can block one of the passages (or do nothing) before Takahashi leaves Room 11. However, it is not allowed to block a passage so that Takahashi is potentially unable to reach Room NN.

Let EE be the expected number of passages Takahashi takes before he reaches Room NN. Find the value of EE when Aoki makes a choice that minimizes EE.

有一个洞穴,由 NN 个房间和 MM 条单向通道组成。房间编号为 11NN

高桥现在在 11 房间 NN 房间有出口 ii 这条通道连接着 sis_i 号房间和 tit_i 号房间( sis_i < tit_i ),只能沿着 sis_i 号房间到 tit_i 号房间的方向穿越。众所周知,除了 NN 室之外,每个房间都至少有一条通道从该房间出去。

高桥将从洞穴中逃脱。每当他到达一个房间时(假设他一开始就到达了 11 号房间),他都会从从该房间出去的通道中均匀随机地选择一条通道并走该通道。

高桥的朋友青木可以在高桥离开 11 房间之前堵住其中一条通道(或者什么都不做)。但是,不允许堵塞通道,这样高桥就有可能无法到达 NN 房间。

EE 是高桥到达 NN 房间之前的预期通道数。求当青木做出最小化 EE 的选择时 EE 的值。

输入格式

输入内容按以下格式标准输入:

NN MM
s1s_1 t1t_1
::
sMs_M tMt_M

输出格式

当青木做出最小化 EE 的选择时,打印 EE 的值。当与法官输出结果的绝对误差或相对误差不超过 10610^{-6} 时,您的输出结果将被判定为正确。

样例 #1

样例输入 #1

4 6
1 4
2 3
1 3
1 2
3 4
2 4

样例输出 #1

1.5000000000

样例 #2

样例输入 #2

3 2
1 2
2 3

样例输出 #2

2.0000000000

样例 #3

样例输入 #3

10 33
3 7
5 10
8 9
1 10
4 6
2 5
1 7
6 10
1 4
1 3
8 10
1 5
2 6
6 9
5 6
5 8
3 6
4 8
2 7
2 9
6 7
1 2
5 9
6 8
9 10
3 9
7 8
4 5
2 10
5 7
3 5
4 7
4 9

样例输出 #3

3.0133333333

说明

数据规模与约定

  • 2N6002 \leq N \leq 600
  • N1MN(N1)2N-1 \leq M \leq \frac{N(N-1)}{2}
  • si<tis_i \lt t_i
  • 如果 i!=ji != j(si,ti)(sj,tj)(s_i, t_i) \neq (s_j, t_j)(添加时间:21:23 JST)
  • 对于每一个 v=1,2,...,N1v = 1, 2, ..., N-1 ,都存在 ii 这样的 v=siv = s_i

样例 11 解释

如果青木封锁了从 11 房间到 22 房间的通道,高桥将沿着134的路径前进,概率为 12\frac{1}{2}14的概率为 12\frac{1}{2} 。这里的 E=1.5E = 1.5EE 的最小可能值。

样例 22 解释

封锁任何一条通道都会导致高桥无法到达 NN 房间,所以青木无法封锁通道。