310719: CF1875F. Jellyfish and EVA
Description
Monsters have invaded the town again! Asuka invites her good friend, Jellyfish, to drive EVA with her.
There are $n$ cities in the town. All the monsters are in city $n$. Jellyfish and Asuka are currently in city $1$ and need to move to city $n$ to defeat the monsters.
There are $m$ roads. The $i$-th road allows one to travel from city $a_i$ to city $b_i$. All the roads are directed. That is, one cannot travel from city $b_i$ to $a_i$ using the $i$-th road. Interestingly, all roads satisfy $a_i<b_i$.
Driving EVA requires two people to work together. However, Asuka and Jellyfish have not done any training together before.
Suppose that EVA is currently in city $u$. Jellyfish and Asuka will both choose an undestroyed road that starts at city $u$. Suppose Jellyfish and Asuka choose roads that end at cities $v_1$ and $v_2$ respectively. If $v_1 = v_2$, EVA moves to city $v_1$ successfully. Otherwise, EVA stays in city $u$ and both roads that they have chosen will be destroyed.
It is possible that EVA is currently in city $u$ ($u \neq n$) and there are no undestroyed roads that start at city $u$. In that case, the mission will be a failure. Otherwise, if they reach city $n$ in the end, the mission is considered a success.
Every time they choose the roads, Jellyfish knows that Asuka will choose a road randomly. Now, Jellyfish wants to know, if she chooses the roads optimally, what is the maximum probability of the mission being successful.
InputEach test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \leq t \leq 2000$). The description of the test cases follows.
The first line of each test case contains two integers, $n$ and $m$ ($2 \leq n \leq 5000$, $0 \leq m \leq \min(\frac{n(n-1)}{2}, 2 \cdot 10^5)$) — the number of the cities and the number of the roads.
In the following $m$ lines of each test case, each line contains two integers $a$ and $b$ ($1 \leq a < b \leq n$) — representing a road from city $a$ to city $b$.
It is guaranteed that for each test case, each road appears at most once.
It is guaranteed that the sum of $n$ over all test cases will not exceed $5000$ and that the sum of $m$ over all test cases will not exceed $2 \cdot 10^5$.
OutputOutput the maximum probability of the mission being successful if Jellyfish chooses the roads optimally.
Your answer will be accepted if the absolute or relative error does not exceed $10^{-9}$. Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is considered correct if $\frac{|a-b|}{\max(1,|b|)} \leq 10^{-9}$.
ExampleInput3 3 2 1 2 1 3 7 8 1 2 1 3 1 4 1 5 2 6 3 6 4 6 6 7 10 20 1 2 1 3 1 4 1 5 1 6 2 6 2 7 2 8 2 9 3 4 3 7 3 8 3 10 4 6 4 8 4 10 6 10 7 8 7 9 7 10Output
0.500000000000 0.625000000000 0.491666666667Note
In the first test case, Jellyfish will choose $v_1=3$, and Asuka will choose $v_2=2$ with a possibility of $0.5$ and $v_2=3$ with a possibility of $0.5$. The mission is considered a success with a possibility of $0.5$.
Output
怪物再次入侵城镇!明日香邀请她的好朋友水母一起驾驶EVA。
城镇中有n个城市,所有怪物都在城市n。水母和明日香目前在城市1,需要移动到城市n击败怪物。
有m条道路。第i条道路允许从城市a_i到城市b_i的旅行。所有道路都是有向的,即不能通过第i条道路从城市b_i到a_i。有趣的是,所有道路满足a_i < b_i。
驾驶EVA需要两个人共同工作。但是,明日香和水母以前没有一起训练过。
假设EVA目前在城市u。水母和明日香都会选择一条从城市u开始的未损坏的道路。假设水母和明日香分别选择结束于城市v_1和v_2的道路。如果v_1 = v_2,EVA成功移动到城市v_1。否则,EVA留在城市u,他们选择的两个道路将被摧毁。
可能EVA目前在城市u(u ≠ n),并且没有从城市u开始的未损坏的道路。在这种情况下,任务将失败。否则,如果他们最终到达城市n,则任务被认为是成功的。
每次他们选择道路时,水母都知道明日香将随机选择一条道路。现在,水母想知道,如果她选择道路最优化,任务成功的最大概率是多少。
输入输出数据格式:
输入:
第一行包含测试用例的数量t(1 ≤ t ≤ 2000)。
每个测试用例的第一行包含两个整数n和m(2 ≤ n ≤ 5000,0 ≤ m ≤ min(n(n-1)/2, 2 * 10^5))——城市的数量和道路的数量。
在接下来的m行中,每行包含两个整数a和b(1 ≤ a < b ≤ n)——代表从城市a到城市b的道路。
保证每个测试用例中,每条道路最多出现一次。
保证所有测试用例的n之和不超过5000,m之和不超过2 * 10^5。
输出:
输出如果水母最优化选择道路,任务成功的最大概率。
如果绝对或相对误差不超过10^-9,则您的答案将被接受。形式上,假设您的答案是a,裁判的答案是b。如果|a-b|/max(1,|b|) ≤ 10^-9,则您的答案被认为是正确的。题目大意: 怪物再次入侵城镇!明日香邀请她的好朋友水母一起驾驶EVA。 城镇中有n个城市,所有怪物都在城市n。水母和明日香目前在城市1,需要移动到城市n击败怪物。 有m条道路。第i条道路允许从城市a_i到城市b_i的旅行。所有道路都是有向的,即不能通过第i条道路从城市b_i到a_i。有趣的是,所有道路满足a_i < b_i。 驾驶EVA需要两个人共同工作。但是,明日香和水母以前没有一起训练过。 假设EVA目前在城市u。水母和明日香都会选择一条从城市u开始的未损坏的道路。假设水母和明日香分别选择结束于城市v_1和v_2的道路。如果v_1 = v_2,EVA成功移动到城市v_1。否则,EVA留在城市u,他们选择的两个道路将被摧毁。 可能EVA目前在城市u(u ≠ n),并且没有从城市u开始的未损坏的道路。在这种情况下,任务将失败。否则,如果他们最终到达城市n,则任务被认为是成功的。 每次他们选择道路时,水母都知道明日香将随机选择一条道路。现在,水母想知道,如果她选择道路最优化,任务成功的最大概率是多少。 输入输出数据格式: 输入: 第一行包含测试用例的数量t(1 ≤ t ≤ 2000)。 每个测试用例的第一行包含两个整数n和m(2 ≤ n ≤ 5000,0 ≤ m ≤ min(n(n-1)/2, 2 * 10^5))——城市的数量和道路的数量。 在接下来的m行中,每行包含两个整数a和b(1 ≤ a < b ≤ n)——代表从城市a到城市b的道路。 保证每个测试用例中,每条道路最多出现一次。 保证所有测试用例的n之和不超过5000,m之和不超过2 * 10^5。 输出: 输出如果水母最优化选择道路,任务成功的最大概率。 如果绝对或相对误差不超过10^-9,则您的答案将被接受。形式上,假设您的答案是a,裁判的答案是b。如果|a-b|/max(1,|b|) ≤ 10^-9,则您的答案被认为是正确的。