P6030 [SDOI2012] Maze Walking

Description

Morenan is trapped in a maze. The maze can be viewed as a directed graph with $n$ vertices and $m$ edges. Morenan starts at vertex $s$, and the exit of the maze is vertex $t$. 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, t$. The next $m$ lines each contain two integers $u, v$, indicating that there is an edge from $u$ to $v$.

Output Format

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

Explanation/Hint

| Test Point | $n\leq$ | $m\leq$ | | :----------: | :----------: | :----------: | | $1\sim 6$ | $10$ | $100$ | | $7\sim 12$ | $200$ | $10^4$ | | $13\sim 20$ | $10^4$ | $10^6$ | In addition, for $40\%$ of the testdata (uniformly distributed), the graph has no cycles and no self-loops. For $100\%$ of the testdata, $1\leq n\leq 10^4$, $0\leq m \leq 10^6$, and it is **guaranteed that the size of each strongly connected component does not exceed** $\boldsymbol{100}$. Translated by ChatGPT 5