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

30164번 - Complete Mirror 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB35131031.250%

문제

You have given tree consist of $n$ vertices. Select a vertex as root vertex that satisfies the condition below.

  • For all vertices $v_{1}$ and $v_{2},ドル if $distance$($root,ドル $v_{1}$) $= distance$($root,ドル $v_{2})$ then $degree$($v_{1}$) $= degree$($v_{2}$), where $degree$ means the number of vertices connected to that vertex, and $distance$ means the number of edges between two vertices.

Determine and find if there is such root vertex in the tree. If there are multiple answers, find any of them.

입력

The first line contains a single integer $n$ (1ドル \le n \le 10^{5}$) --- the number of vertices.

Each of the next $n-1$ lines contains two integers $v_{i}$ and $u_{i}$ (1ドル \le v_{i} \lt u_{i} \le n$) --- it means there is an edge exist between $v_{i}$ and $u_{i}$. It is guaranteed that the graph forms tree.

출력

If there is such root vertex exists, print any of them. Otherwise, print $-1$.

제한

예제 입력 1

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

예제 출력 1

3

예제 입력 2

6
1 3
2 3
3 4
4 5
4 6

예제 출력 2

-1

노트

This is the picture for the first example. 1ドル,ドル 5ドル,ドル 7ドル$ also can be a valid answer.

This is the picture for the second example. You can see that it's impossible to find such root vertex.

출처

Contest > Codeforces > Codeforces Round 566 (Div. 2) D번

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

출처

대학교 대회

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

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