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

34524번 - Tree Decorations 서브태스크다국어

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

문제

Mateo recently found the perfect decorations for his Christmas tree — more trees!

Specifically, his Christmas tree is a rooted tree $T$ initially with $M$ nodes, all painted green. He has another rooted tree $D$ that he uses as a reference for his decorations. Mateo uses the following process to put on all of his decorations:

  • For each node $i$ in $D,ドル he creates a copy of the subtree rooted at $i$. Let this copy be $C_i$. Then, he paints the nodes of $C_i$ red. Finally, he chooses some green node in $T$ to be the parent of the root of $C_i$ by connecting them with an edge.

After applying all the decorations, $T$ ends up containing $N$ nodes. Unfortunately, he realized that he had forgotten to record what $D$ is! To make things worse, he accidentally spilled water on $T,ドル washing off all the colour from the nodes. After all that, he labels the root of $T$ as 1ドル,ドル and then labels the rest of the nodes from 2ドル$ to $N$.

The only information he currently has is the final state of $T,ドル as well as $M$. Help him find the number of possible $D$ that he could have started with, where two possibilities are considered different if they are structurally distinct.

Rooted trees $A$ and $B$ are said to be structurally identical if and only if they have the same number of nodes $S,ドル and there is a way to label $A$’s nodes from 1ドル$ to $S$ and $B$’s nodes from 1ドル$ to $S$ such that:

  • Their roots are labeled the same.
  • Nodes labeled $x$ and $y$ in $A$ are connected by an edge if and only if nodes labeled $x$ and $y$ in $B$ are connected by an edge.

Otherwise, $A$ and $B$ are considered structurally distinct.

입력

The first line of input contains two space-separated integers $N$ and $M$.

The next $N − 1$ lines each contain two space-separated integers $u_i$ and $v_i$ (1ドル ≤ u_i , v_i ≤ N,ドル $u_i \ne v_i$), describing an edge in $T$ connecting nodes $u_i$ and $v_i$. Note that $T$ is rooted at node 1ドル$.

출력

Output the number of possible $D$ that he could have started with, where two possibilities are considered different if they are structurally distinct.

제한

서브태스크

번호배점제한
12

2ドル ≤ N ≤ 10,ドル $M = 1$

23

2ドル ≤ N ≤ 200,ドル $M = 1$

32

2ドル ≤ N ≤ 500,円 000,ドル $M = 1$

46

2ドル ≤ N ≤ 200,ドル 1ドル ≤ M < N$

54

2ドル ≤ N ≤ 2,円 000,ドル 1ドル ≤ M < N$

68

2ドル ≤ N ≤ 500,円 000,ドル 1ドル ≤ M < N$

예제 입력 1

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

예제 출력 1

1

It is provable that the only possible $D$ is:

We can get $T$ the following way:

In the diagram above, the red parts are added as decorations, while the green, filled-in part represents the initial state of $T$. The dotted lines represent the edges connecting the decorations to the tree.

예제 입력 2

14 5
1 2
1 3
3 4
3 5
1 6
6 7
7 8
7 9
2 10
10 11
10 12
10 13
10 14

예제 출력 2

2

The first possibility for $D$ is:

Using this, we can get $T$ the following way:

The second possibility for $D$ is:

Using this, we can get $T$ the following way:

노트

출처

Olympiad > Canadian Computing Competition & Olympiad > 2025 > CCO 2025 2번

채점 및 기타 정보

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

출처

대학교 대회

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

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