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

28045번 - Favorite Tree 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
0.1 초 1024 MB74393454.839%

문제

After learning about tree isomorphism, Telio couldn’t avoid but wonder in how many trees out there his favorite tree is hiding.

Given two trees, $T_1$ and $T_2,ドル can you help him determine if there is a subtree of $T_1$ isomorphic to $T_2$?

Two trees are isomorphic if it is possible to label their vertices in such a way that they become exactly the same tree. For instance, a tree having edges $\{(1, 2),(2, 3)\}$ is isomorphic to a tree having edges $\{(1, 3),(3, 2)\}$.

The figure below corresponds to the first sample, with tree $T_1$ on the left and tree $T_2$ on the right. The subtree of $T_1$ formed by all of its vertices but vertex 5ドル$ is isomorphic to $T_2$.

입력

There are two groups of lines, each group describing a tree. The first group describes the tree $T_1,ドル while the second group describes the tree $T_2$.

Within each group describing a tree, the first line contains an integer $N$ (1ドル ≤ N ≤ 100$) representing the number of vertices in the tree. Vertices are identified by distinct integers from 1ドル$ to $N$. Each of the next $N - 1$ lines contains two integers $U$ and $V$ (1ドル ≤ U, V ≤ N$ and $U \ne V$), indicating that the tree has the edge $(U, V)$.

It is guaranteed that the input describes two valid trees.

출력

Output a single line with the uppercase letter “Y” if there is a subtree of $T_1$ that is isomorphic to $T_2,ドル and the uppercase letter “N” otherwise.

제한

예제 입력 1

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

예제 출력 1

Y

예제 입력 2

4
2 3
2 1
2 4
4
1 2
2 3
3 4

예제 출력 2

N

예제 입력 3

1
1

예제 출력 3

Y

힌트

출처

ICPC > Regionals > Latin America > Latin America Regional Contests > Latin America Regional Contests 2022 F번

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

출처

대학교 대회

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

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