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

23169번 - Mission Impossible: Grand Theft Auto 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB1000.000%

문제

Tom Cruise had his car stolen during the filming in Birmingham. You, as the chief police officer, are asked to catch the thief.

Your people are patrolling the countryside, so the criminal can only be in one of $n$ towns, and the highways between them represent a tree --- that is, there are $n - 1$ bidirectional roads each connecting a pair of towns, and it is possible to traverse from each of them to any other. On each day you can pick any two towns $A$ and $B$ (not necessarily distinct) and request a troop which will check every town on the simple path between $A$ and $B$ (including both of them). If the thief is in one of these towns then it's game over for him. Otherwise, later that night he can move into any other adjacent town by a single road or stay still in the town where he was.

Since this is a very important case, you are very short of time. More specifically, let $m$ be the number of leaves in the tree (that is, towns with only one outgoing road). Then you have to come up with a plan of $\lfloor m/2 \rfloor + 1$ days which catches the thief: for each day you tell the corresponding $A$ and $B$ for this day, and your goal is to catch the guy independently on his actions between the days.

Find a plan satisfying the requirements. You will have to answer several test cases.

입력

The first line of input contains the only integer $T$ (1ドル \leq T \leq 100$) --- the number of test cases. $T$ tests follow.

The first line of each test case contains a single integer $n$ (2ドル \leq n \leq 2 \cdot 10^5$) --- the number of towns. Each of the next $n - 1$ lines consists of two integers $u$ and $v$ separated by space (1ドル \leq u, v \leq n$), denoting a road between towns $u$ and $v$.

It is guaranteed that each test case represents a tree, and that the sum of all $n$ does not exceed 2ドル \cdot 10^5$.

출력

For each test case, print exactly $\lfloor m/2 \rfloor + 1$ lines, each consisting of two integers $A$ and $B$ (1ドル \le A, B \le n$) denoting the endpoints of the corresponding path. If you are sure that you can catch the thief using less operations, just add arbitrary paths at the bottom. One can prove that an answer always exists under these constraints.

제한

예제 입력 1

4
5
1 2
1 3
1 4
1 5
4
1 2
2 3
3 4
5
1 2
1 3
2 4
2 5
6
1 2
2 3
2 4
4 5
4 6

예제 출력 1

1 2
1 3
4 5
1 3
2 4
2 3
4 5
1 3
2 4
5 6

노트

Extra lines in the sample output are to visually separate answers for different cases. You do not have to print them.

출처

Camp > Petrozavodsk Programming Camp > Summer 2021 > Day 7: Moscow IPT Contest K번

Contest > Open Cup > 2021/2022 Season > Stage 1: Grand Prix of Dolgoprudny K번

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

출처

대학교 대회

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

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