2014 Beijing Network qualifiers 1005 (strong connectivity contraction point + expectation) hdu5036

Source: Internet
Author: User
Explosion Time Limit: 6000/3000 MS (Java/others) memory limit: 262144/262144 K (Java/Others)
Total submission (s): 243 accepted submission (s): 63


Problem descriptioneveryone knows Matt enjoys playing games very much. now, he is playing such a game. there are n rooms, each with one door. there are some keys (cocould be none) in each room corresponding to some doors among these N doors. every key can open only one door. matt has some bombs, each of which can destroy a door. he will uniformly choose a door that can not be opened with the keys in his hand to destroy when there are no doors that can be opened with keys in his hand. now, he wants to ask you, what is the expected number of bombs he will use to open or destroy all the doors. rooms are numbered from 1 to n.
Inputthe first line of the input contains an integer T, denoting the number of testcases. Then T test cases follow.

In the first line of each test case, there is an integer n (n <= 1000) indicating the number of rooms.

The following n lines corresponde to the rooms from 1 to n. each line begins with an integer K (0 <= k <= N) indicating the number of keys behind the door. then K integers follow corresponding to the rooms these keys can open.
Outputfor each test case, output one line "case # X: Y", where X is the case number (starting from 1 ), Y is the answer which shocould be rounded to 5 decimal places.
Sample Input
231 21 31 13000
 
Sample output
Case #1: 1.00000Case #2: 3.00000

Question: RT
Idea: if a door is opened, the door containing the key must be opened.
It is easy to think that if a ring exists, select any door in the ring to open the whole ring.
First, the forced connection point is reduced to a Dag.
As long as the DFS processes the points that can be reached, this can be maintained using bitset.
Then we need to calculate the expectation of opening all the doors. In fact, we need to calculate the expectation of opening each door, and then add up.
For door I, if there are X doors that can reach it, the probability of opening it is CNT [I]/X, which is expected to be CNT [I]/X, the door here is already after the strongly connected contraction point, and CNT [I] is the number of doors in I

2014 Beijing Network qualifiers 1005 (strong connectivity contraction point + expectation) hdu5036

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.