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

30177번 - Edge Weight Assignment 다국어

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

문제

You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold:

  • For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to 0ドル$.

Note that you can put very large positive integers (like 10ドル^{(10^{10})}$).

It's guaranteed that such assignment always exists under given constraints. Now let's define $f$ as the number of distinct weights in assignment.

In this example, assignment is valid, because bitwise XOR of all edge weights between every pair of leaves is 0ドル$. $f$ value is 2ドル$ here, because there are 2ドル$ distinct edge weights(4ドル$ and 5ドル$).

In this example, assignment is invalid, because bitwise XOR of all edge weights between vertex 1ドル$ and vertex 6ドル$ (3,ドル 4, 5, 4$) is not 0ドル$.

What are the minimum and the maximum possible values of $f$ for the given tree? Find and print both.

입력

The first line contains integer $n$ (3ドル \le n \le 10^{5}$) --- the number of vertices in given tree.

The $i$-th of the next $n-1$ lines contains two integers $a_{i}$ and $b_{i}$ (1ドル \le a_{i} \lt b_{i} \le n$) --- it means there is an edge between $a_{i}$ and $b_{i}$. It is guaranteed that given graph forms tree of $n$ vertices.

출력

Print two integers --- the minimum and maximum possible value of $f$ can be made from valid assignment of given tree. Note that it's always possible to make an assignment under given constraints.

제한

예제 입력 1

6
1 3
2 3
3 4
4 5
5 6

예제 출력 1

1 4

예제 입력 2

6
1 3
2 3
3 4
4 5
4 6

예제 출력 2

3 3

예제 입력 3

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

예제 출력 3

1 6

노트

In the first example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.

In the second example, possible assignments for each minimum and maximum are described in picture below. The $f$ value of valid assignment of this tree is always 3ドル$.

In the third example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.

출처

Contest > Codeforces > Codeforces Round 633 (Div. 1) B번

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

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

출처

대학교 대회

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

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