#P7113. [NOIP2020] 排水系统

    ID: 6166 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>图论高精度2020NOIp 提高组拓扑排序

[NOIP2020] 排水系统

Description

For a city, the drainage system is an extremely important part.

One day, Xiao C obtained the design blueprint of a city's drainage system. The drainage system consists of nn drainage nodes (numbered from 1n1 \sim n) and several one-way drainage pipes. Each drainage node has some pipes to collect sewage from other drainage nodes (called the incoming pipes of this node), and also some pipes to discharge sewage to other drainage nodes (called the outgoing pipes of this node).

Among the nodes of the drainage system, there are mm sewage inlets, with indices 1,2,,m1, 2, \ldots , m. Sewage can only enter the drainage system from these inlets, and these nodes have no incoming pipes. The drainage system also has some final outlets that transport sewage to the sewage treatment plant. A node with no outgoing pipes can be regarded as a final outlet.

Now, each sewage inlet receives 11 ton of sewage. After sewage enters a node, it will be evenly distributed along each outgoing pipe of the current node to other drainage nodes, while final outlets will discharge the sewage out of the system.

Now Xiao C wants to know how much sewage each final outlet will discharge in this city's drainage system. The design of the drainage system is sound: the pipes will not form cycles, i.e., there will be no circular flow of sewage.

Input Format

The first line contains two integers n,mn, m separated by a single space, representing the number of drainage nodes and the number of inlets.
The next nn lines describe the outgoing pipes of each node. In the ii-th line, the first integer did_i denotes the number of outgoing pipes. Then did_i integers a1,a2,,adia_1, a_2, \ldots , a_{d_i} separated by single spaces follow, indicating the target drainage nodes of these pipes in order.
It is guaranteed that there will not be two pipes with the same start node and the same target node.

Output Format

Output several lines. In increasing order of node index, output the amount of sewage discharged by each final outlet. The amount should be printed as a fraction: each line outputs two integers pp, qq separated by a single space, meaning the discharged amount is pq\frac{p}{q}. It is required that pp and qq are coprime. When q=1q = 1, you still need to output qq.

5 1
3 2 3 5
2 4 5
2 5 4
0
0

1 3
2 3

见附件中的 water/water2.in
见附件中的 water/water2.ans
见附件中的 water/water3.in
见附件中的 water/water3.ans

Hint

[Sample #1 Explanation]

Node 11 is an inlet, and nodes 4,54, 5 have no outgoing pipes, so they are final outlets.
After 11 ton of sewage flows into node 11, it is evenly distributed to nodes 2,3,52, 3, 5, so each of the three nodes receives 13\frac{1}{3} ton of sewage.
The 13\frac{1}{3} ton of sewage that flows into node 22 will be evenly distributed to nodes 4,54, 5, so each of the two nodes receives 16\frac{1}{6} ton of sewage.
The 13\frac{1}{3} ton of sewage that flows into node 33 will be evenly distributed to nodes 4,54, 5, so each of the two nodes receives 16\frac{1}{6} ton of sewage.
Finally, node 44 discharges 16+16=13\frac{1}{6} + \frac{1}{6} = \frac{1}{3} ton of sewage, and node 55 discharges $\frac{1}{3} + \frac{1}{6} + \frac{1}{6} = \frac{2}{3}$ ton of sewage.

[Constraints]

Test Point ID nn \le mm \le
131 \sim 3 1010 11
464 \sim 6 103{10}^3
787 \sim 8 105{10}^5
9109 \sim 10 1010

For all test points, it is guaranteed that 1n1051 \le n \le {10}^5, 1m101 \le m \le 10, and 0di50 \le d_i \le 5.

The testdata guarantees that in the process of sewage flowing from an inlet to a final outlet, it will not pass through more than 1010 intermediate drainage nodes (i.e., excluding the inlet and the final outlet).

Translated by ChatGPT 5