#P15508. [CEOI 2012] Network
[CEOI 2012] Network
Description
Our engineers have designed a communication network that consists of nodes and unidirectional direct communication channels (links) between some pairs of nodes. We say that a node is reachable from node on a path, if there is a sequence of different nodes with and , such that there is a link that transmits data from to for every . This network has a central node , such that any other node can be reached from via a path, and for any pair of nodes and there is at most one path on which can be reached from . The maintainers plan to improve on the network, but have not yet decided how. One idea they are considering is to reassign the central node, therefore they want to know for each node how many nodes are reachable from it on a path. Another idea is to just decentralize the network, so they also want to know how they could introduce new links so that for any pair of nodes and , there is exactly one path on which the node can be reached from , and vice versa.
You are to write a program that computes the number of reachable nodes for every node (Subtask A), and also computes the minimum number of new links needed to make every node reachable in a unique way from every other node. Your program must give the list of new links, too (Subtask B).
Input Format
The first line of the input contains three integers, () the number of nodes, () the number of links, and () the central node. Nodes are numbered from to . The next lines contain the description of the links. Each line contains two integers and separated by space, that corresponds to a link, which can transmit data from to .
Output Format
The first line of the output contains the solution to Subtask A: integers separated by space, where the th number is the number of reachable nodes from node (including itself). The remaining lines contain the solution for Subtask B: The second line of the output contains one integer , the minimum number of new links needed to achieve the above property of the network. The next lines list the new links: each of lines contains two integers and separated by space, that corresponds to a new link transmitting data from node to node . If there are multiple solutions, your program should output only one; it does not matter which one.
11 12 3
3 2
2 1
2 4
4 5
4 6
6 2
6 7
3 8
8 9
9 10
9 11
10 8
1 6 11 6 1 6 1 4 4 4 1
5
1 3
5 4
7 6
11 9
8 3
Hint
Grading
In of the test cases is at most .
Subtask A is worth of the points, Subtask B is worth the other of the points.
If you only solve Subtask B, you must write integers in the first line.
京公网安备 11011102002149号