#P6030. [SDOI2012] 走迷宫

[SDOI2012] 走迷宫

Description

Morenan is trapped in a maze. The maze can be viewed as a directed graph with nn vertices and mm edges. Morenan starts at vertex ss, and the exit of the maze is vertex tt.

Unfortunately, Morenan is not very smart. From a vertex, he will randomly choose one outgoing directed edge from that vertex and move to the next vertex. In this way, the number of steps Morenan takes may be very large, may be infinite, and it is even possible that he will never reach the exit. If he cannot reach the exit, then the number of steps is considered infinite. You must find the expected number of steps Morenan takes.

Input Format

The first line contains four integers n,m,s,tn, m, s, t.

The next mm lines each contain two integers u,vu, v, indicating that there is an edge from uu to vv.

Output Format

Output one floating-point number, rounded to 33 digits after the decimal point, representing the expected number of steps. If the expected value is infinite, output INF.

6 6 1 6
1 2
1 3
2 4
3 5
4 6
5 6
3.000
9 12 1 9
1 2
2 3
3 1
3 4
3 7
4 5
5 6
6 4
6 7
7 8
8 9
9 7
9.500
2 0 1 2
INF

Hint

Test Point nn\leq mm\leq
161\sim 6 1010 100100
7127\sim 12 200200 10410^4
132013\sim 20 10410^4 10610^6

In addition, for 40%40\% of the testdata (uniformly distributed), the graph has no cycles and no self-loops.

For 100%100\% of the testdata, 1n1041\leq n\leq 10^4, 0m1060\leq m \leq 10^6, and it is guaranteed that the size of each strongly connected component does not exceed 100\boldsymbol{100}.

Translated by ChatGPT 5