#P11046. [蓝桥杯 2024 省 Java B] 星际旅行
[蓝桥杯 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 planets in this star system, and bidirectional portals are set up. The -th portal connects planets and (, and between any two planets there is at most one portal).
He is interested in a “travel blind box”. There are blind boxes in total. The travel plan in the -th blind box specifies the starting planet and the maximum number of portal uses . 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 lines of input.
The first line contains three positive integers .
The next lines each contain two positive integers .
The next lines each contain two integers .
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 .
- The second blind box can visit .
- The third blind box can visit .
So the expectation is .
[Constraints]
- For of the test cases, is guaranteed.
- For of the test cases, , , , , and are guaranteed.
Translated by ChatGPT 5