CF1874C.Jellyfish and EVA

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Monsters have invaded the town again! Asuka invites her good friend, Jellyfish, to drive EVA with her.

There are nn cities in the town. All the monsters are in city nn. Jellyfish and Asuka are currently in city 11 and need to move to city nn to defeat the monsters.

There are mm roads. The ii-th road allows one to travel from city aia_i to city bib_i. All the roads are directed. That is, one cannot travel from city bib_i to aia_i using the ii-th road. Interestingly, all roads satisfy ai<bia_i \lt 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 uu. Jellyfish and Asuka will both choose an undestroyed road that starts at city uu. Suppose Jellyfish and Asuka choose roads that end at cities v1v_1 and v2v_2 respectively. If v1=v2v_1 = v_2, EVA moves to city v1v_1 successfully. Otherwise, EVA stays in city uu and both roads that they have chosen will be destroyed.

It is possible that EVA is currently in city uu (u≠nu \neq n) and there are no undestroyed roads that start at city uu. In that case, the mission will be a failure. Otherwise, if they reach city nn 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.

怪物再次入侵了小镇!明日香邀请她的好朋友水母一起驾驶EVA。

小镇共有 nn 座城市,所有怪物都聚集在第 nn 座城市。明日香和水母当前位于第 11 座城市,需要前往第 nn 座城市击败怪物。

小镇中有 mm 条道路。第 ii 条道路允许从城市 aia_i 单向通行至城市 bib_i。所有道路均为有向边,即无法通过第 ii 条道路从城市 bib_i 返回城市 aia_i。有趣的是,所有道路均满足 ai<bia_i \lt b_i。

驾驶EVA需两人协同操作。然而,明日香与水母此前从未进行过联合训练。

假设当前EVA位于城市 uu。此时,水母与明日香各自独立选择一条尚未被摧毁、且起点为城市 uu 的道路。设水母与明日香所选道路的终点分别为 v1v_1 和 v2v_2。若 v1=v2v_1 = v_2,则EVA成功移动至城市 v1v_1;否则,EVA仍停留在城市 uu,且二人所选的这两条道路将同时被摧毁。

有可能出现如下情形:EVA当前位于城市 uu(其中 u≠nu \neq n),但城市 uu 出发的所有未被摧毁的道路均已不存在。此时任务失败。否则,若最终成功抵达城市 nn,则任务视为成功。

每次选择道路时,水母知道明日香将随机选择一条可选道路。现在,水母希望知道:若她每次都以最优策略选择道路,任务成功的最大概率是多少?

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤20001 \leq t \leq 2000). The description of the test cases follows.

The first line of each test case contains two integers, nn and mm (2≤n≤50002 \leq n \leq 5000, 0≤m≤min⁡(n(n−1)2,2⋅105)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 mm lines of each test case, each line contains two integers aa and bb (1≤a<b≤n1 \leq a \lt b \leq n) — representing a road from city aa to city bb.

It is guaranteed that for each test case, each road appears at most once.

It is guaranteed that the sum of nn over all test cases will not exceed 50005000 and that the sum of mm over all test cases will not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤20001 \leq t \leq 2000)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 mm(2≤n≤50002 \leq n \leq 5000,0≤m≤min⁡(n(n−1)2,2⋅105)0 \leq m \leq \min(\frac{n(n-1)}{2}, 2 \cdot 10^5)),分别表示城市的数量和道路的数量。

在每个测试用例接下来的 mm 行中,每行包含两个整数 aa 和 bb(1≤a<b≤n1 \leq a \lt b \leq n),表示一条从城市 aa 到城市 bb 的道路。

保证在每个测试用例中,每条道路至多出现一次。

保证所有测试用例的 nn 之和不超过 50005000,且所有测试用例的 mm 之和不超过 2⋅1052 \cdot 10^5。

输出格式

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−910^{-9}. Formally, let your answer be aa, and the jury's answer be bb. Your answer is considered correct if ∣a−b∣max⁡(1,∣b∣)≤10−9\frac{|a-b|}{\max(1,|b|)} \leq 10^{-9}.

如果水母(Jellyfish)最优地选择道路,输出任务成功的最大概率。

若你的答案的绝对误差或相对误差不超过 10−910^{-9},则该答案将被接受。形式化地说,设你的答案为 aa,评测组的答案为 bb,当且仅当 ∣a−b∣max⁡(1,∣b∣)≤10−9\frac{|a-b|}{\max(1,|b|)} \leq 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=3v_1=3, and Asuka will choose v2=2v_2=2 with a possibility of 0.50.5 and v2=3v_2=3 with a possibility of 0.50.5. The mission is considered a success with a possibility of 0.50.5.

在第一个测试用例中,Jellyfish 将选择 v1=3v_1=3,而 Asuka 将以 0.50.5 的概率选择 v2=2v_2=2,以 0.50.5 的概率选择 v2=3v_2=3。任务成功的概率为 0.50.5。

输入解题思路,AI测评打分。不知道怎么写?

首页