QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 128 MB Points totaux : 100

#4138. Maze Exploration

Statistiques

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 destination is $T$.

Unfortunately, Morenan is not very bright. He only moves by choosing one of the outgoing edges from his current vertex uniformly at random and moving to the next vertex. As a result, the number of steps Morenan takes could be very large, infinite, or he might never reach the destination. If he cannot reach the destination, the number of steps is considered to be infinity. You must find the expected number of steps Morenan takes.

Input

The first line contains four integers $N, M, S, T$.

Each of the next $M$ lines contains two integers $o_1, o_2$, representing a directed edge from $o_1$ to $o_2$.

Output

A single floating-point number, rounded to 3 decimal places, representing the expected number of steps. If the expected value is infinity, output INF.

Examples

Input 1

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

Output 1

3.000

Input 2

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

Output 2

9.500

Input 3

2 0 1 2

Output 3

INF

Subtasks

Test Cases $N$ $M$ Constraints
$1 \sim 2$ $\leq 10$ $\leq 10$
$3 \sim 6$ $\leq 12$ $\leq 20$
$7 \sim 8$ $\leq 200$ $\leq 1\,000$
$9 \sim 12$ $\leq 200$ $\leq 10\,000$
$13 \sim 20$ $\leq 10\,000$ $\leq 1\,000\,000$ The size of each strongly connected component is at most $100$

Additionally, $40\%$ of the test cases are guaranteed to have no cycles and no self-loops.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.