프로그램 명: ceoi_network(special judge)
제한시간: 1 초
sj 가 아직 ...

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 q is reachable from node p on a path, if there is a sequence of different nodes p1,p2,…,pk with p=p1 and q=pk, such that there is a link that transmits data from pi to pi+1 for every i=1,…,k-1.

This network has a central node r, such that any other node p can be reached from r via a path, and for any pair of nodes p and q there is at most one path on which q can be reached from p. 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 p and q, there is exactly one path on which the node q can be reached from p, and vice versa.

Task

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).

입력

출력

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


▒ 대회 제한시간은 0.1 초 입니다.
출처:ceoi 2012

[질/답] [제출 현황] [푼 후(0)]
[ 채 점 ] [홈으로]  [뒤 로]