-->
当前位置:首页 > 题库

PROGRAMMING:drainage system

Luz5年前 (2021-05-10)题库540
For a city, the drainage system is an extremely important part.
One day, little c got the design drawing of a city's drainage system. The drainage system consists of $$n $$drainage nodes (which are numbered from $$1 / SIM n $) and several unidirectional drainage pipes. Each drainage node has several pipes for collecting the sewage of other drainage nodes (referred to as the collection pipe of the node), and several pipes discharge sewage to other drainage nodes (referred to as the discharge pipe of the node).
There are $$M $$sewage receiving ports in the nodes of the drainage system, and their numbers are $$1, 2, ldots, M $$. Sewage can only flow into the drainage system from these receiving ports, and these nodes have no collecting pipes. There are several final outlets in the drainage system, which transport the sewage to the sewage treatment plant. The node without discharge pipe can be regarded as a final outlet.
Now each sewage receiving port receives $$1 $$tons of sewage respectively. After sewage enters each node, it will equally flow from each discharge pipe of the current node to other drainage nodes, and the final outlet will discharge the sewage into the system.
Now little c wants to know how much sewage will be discharged from each final outlet in the city's drainage system. The city's drainage system design is scientific, the pipeline will not form a loop, that is, there will be no sewage circulation.
###Input format:
The first two integers $$n, M $$separated by a single space. It represents the number of drainage nodes and the number of receiving ports respectively.
Next, line $$n $, line $$I $, is used to describe all the discharge pipes of node $$I $. Where the first integer of each row is $d_ I $denotes the number of discharge pipes, followed by $$d_ I $$integers separated by a single space $$a_ 1, a_ 2, \ldots , a_{ d_ i} $$represents the target drainage node of the pipeline in turn.
It is guaranteed that there will not be two pipelines with the same starting node and target node.
###Output format:
Output several lines, according to the number from small to large order, give the volume of sewage discharged from each final outlet. The volume is output in fractional form, that is, two integers, $$p $, $$q $, separated by a single space are output in each line, indicating that the volume of discharged sewage is $$- frac {P} {Q} $$. The mutual prime of $$p $$and $$q $$is required, and the output of $$q $$is also required when $$q = 1 $.
###Input sample 1:
```in
5 1
3 2 3 5
2 4 5
2 5 4
0
0
```
###Output sample 1:
```out
1 3
2 3
```
###[example 1 explanation]
Node $$1 is the receiving port, node $$4 and node $$5 have no discharge pipe, so they are the final drainage port.
After the $$1 $$ton sewage flows into node $$1 $, it flows to node $$2,3,5 $$equally, and each of the three nodes flows into $$frac {1} {3} $$ton sewage.
The inflow of $$$frac {1} {3} $$tons of sewage from node $$2 $$will equally flow to node $$4 and 5 $, and each node will flow into $$$frac {1} {6} $$tons of sewage.
The inflow of $$- frac {1} {3} $$tons of sewage from node $$3 will flow equally to node $$4 and node $$5, and each node will flow into $$- frac {1} {6} $$tons of sewage.
Finally, $$4 $$node discharges $$- frac {1} {6} + - frac {1} {6} = - frac {1} {3} $$tons of sewage, and $$5 $$node discharges $$- frac {1} {3} + - frac {1} {6} + - frac {1} {6} = - frac {2} {3} $$tons of sewage.
###Example 2
See water2. In and water2. ANS in the attached file.
###Example 3
See water3. In and water3. ANS in the attached file.
###[data range]
|Test point number|
|:-:|:-:|:-:|
| $$1 \sim 3$$ | $$10$$ | $$1$$ |
| $$4 \sim 6$$ | $${10}^3$$ | $$1$$ |
| $$7 \sim 8$$ | $${10}^5$$ | $$1$$ |
| $$9 \sim 10$$ | $${10}^5$$ | $$10$$ |
For all test points, ensure that $$1 / Le n / Le {10} ^ 5 $$, $$1 / Le M / Le 10 $$, $$0 / Le D_ i \le 5$$。
The data guarantee that the sewage will not pass through more than $$10 $$intermediate drainage nodes in the process of flowing from a receiving port to a final drainage port (that is, the receiving port and final drainage port are not included)< br>





answer:If there is no answer, please comment