#P11046. [蓝桥杯 2024 省 Java B] 星际旅行

    ID: 12398 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>2024广度优先搜索 BFS概率论期望蓝桥杯省赛

[蓝桥杯 2024 省 Java B] 星际旅行

Background

Note: In the original problem (Java), the time limit is 3.0 s and the memory limit is 512 MB.

Problem Description

Xiaoming plans to take an interstellar trip to a certain star system during the National Day holiday. There are nn planets in this star system, and mm bidirectional portals are set up. The ii-th portal connects planets aia_i and bib_i (aibia_i \neq b_i, and between any two planets there is at most one portal).

He is interested in a “travel blind box”. There are QQ blind boxes in total. The travel plan in the ii-th blind box specifies the starting planet xix_i and the maximum number of portal uses yiy_i. Starting from the given planet, all planets that can be reached using portals no more than the allowed number of times can be visited.

Xiaoming cares about how many planets can be visited under each plan. He can only randomly choose one blind box to buy, and he wants to know the expected number of different planets he can visit.

Input Format

There are m+Q+1m + Q + 1 lines of input.

The first line contains three positive integers n,m,Qn, m, Q.

The next mm lines each contain two positive integers ai,bia_i, b_i.

The next QQ lines each contain two integers xi,yix_i, y_i.

Output Format

Output one line containing a floating-point number (rounded to two decimal places).

3 2 3
1 2
2 3
2 1
2 0
1 1
2.00

Hint

[Sample Explanation]

  • The first blind box can visit 1,2,31, 2, 3.
  • The second blind box can visit 22.
  • The third blind box can visit 1,21, 2.

So the expectation is (3+1+2)/3=2.00(3 + 1 + 2) / 3 = 2.00.

[Constraints]

  • For 20%20\% of the test cases, n300n \leq 300 is guaranteed.
  • For 100%100\% of the test cases, n1000n \leq 1000, mmin{n(n1)2,5n}m \leq \min \left\{\dfrac{n(n - 1)}{2}, 5n\right\}, Q50000Q \leq 50000, 0yin0 \leq y_i \leq n, and 1xin1 \leq x_i \leq n are guaranteed.

Translated by ChatGPT 5