Logo
(追記) (追記ここまで)

10780번 - Network 서브태스크스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 256 MB81433149.206%

문제

The government of Byteland has decided that it is time to connect their little country to the Internet, so that all citizens can participate in programming competitions and watch videos of cute cats. When it was time to build the network backbone of the country, they assigned the company Internet Optimists Inc. with connecting all the n computers of Byteland. The connections were made as direct links between pairs of computers in such a way that any pair of computers are connected by a sequence of links.

Byteland is not a rich country by any means, so to minimize costs the network topology was built in the form of a tree (i.e. there are exactly n − 1 direct links between computers). Far too late, it was realised that this solution suffers from a serious drawback. If just a single link is broken, the computers of Byteland will be partitioned so that some computers cannot communicate with each other!

To improve the reliability of Byteland’s network, it was decided that it should at least tolerate if a single link is broken. Your task is to help Internet Optimists Inc. to improve the network in a cheapest way. Given the network topology of Byteland (i.e. which n − 1 pairs of computers are connected by direct links), find the minimum number of links that need to be added so that the network will still be connected if any single link is broken.

입력

The first line of input contains a positive integer n (n ≥ 3), the number of computers in Byteland. For simplicity, all computers are numbered from 1 to n. Each of the following n−1 lines contains a pair of integers a and b (1 ≤ a, b ≤ n, a ≠ b) that describes a direct link between computers a and b.

출력

In the first line of output your program should write an integer k, the minimal number of links that should be added to the network. In each of the following k lines your program should write a pair of integers a and b (1 ≤ a, b ≤ n, a ≠ b) that denote the numbers of computers that should be connected by a link. The links can be written in any order. If there is more than one solution, your program should output any one of them.

제한

서브태스크

번호배점제한
118

n ≤ 10

245

n ≤ 2000

337

n ≤ 500 000

예제 입력 1

6
1 2
2 3
2 4
5 4
6 4

예제 출력 1

2
1 5
3 6

예제 입력 2

8
1 2
2 3
3 4
4 5
3 6
3 7
3 8

예제 출력 2

3
1 6
5 7
8 4

힌트

출처

Olympiad > Baltic Olympiad in Informatics > BOI 2015 3번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /