CF1874C.Jellyfish and EVA
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 ai to city bi . All the roads are directed. That is, one cannot travel from city bi to ai using the i -th road. Interestingly, all roads satisfy ai<bi .
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 v1 and v2 respectively. If v1=v2 , EVA moves to city v1 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=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.
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t ( 1≤t≤2000 ). The description of the test cases follows.
The first line of each test case contains two integers, n and m ( 2≤n≤5000 , 0≤m≤min(2n(n−1),2⋅105) ) — 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≤a<b≤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⋅105 .
输出格式
Output 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 max(1,∣b∣)∣a−b∣≤10−9 .
输入输出样例
输入#1
3 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 10
输出#1
0.500000000000 0.625000000000 0.491666666667
说明/提示
In the first test case, Jellyfish will choose v1=3 , and Asuka will choose v2=2 with a possibility of 0.5 and v2=3 with a possibility of 0.5 . The mission is considered a success with a possibility of 0.5 .