아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Favorite Tree

시간 제한0.1초메모리 제한1024 MB

요약
두 트리가 주어질 때 첫 번째 트리의 부분트리 중 두 번째 트리와 동형인 것이 있는지 판정한다.
난이도

보통10점 중 7점

유형
트리, DFS, 해시맵, 구현
정답자
아직 제출이 없습니다

문제

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_1T\_1 and T_2T\_2, can you help him determine if there is a subtree of T_1T\_1 isomorphic to T_2T\_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)\\{(1, 2),(2, 3)\\} is isomorphic to a tree having edges (1,3),(3,2)\\{(1, 3),(3, 2)\\}.

The figure below corresponds to the first sample, with tree T_1T\_1 on the left and tree T_2T\_2 on the right. The subtree of T_1T\_1 formed by all of its vertices but vertex 55 is isomorphic to T_2T\_2.

입력

There are two groups of lines, each group describing a tree. The first group describes the tree T_1T\_1, while the second group describes the tree T_2T\_2.

Within each group describing a tree, the first line contains an integer NN (1≤N≤1001 ≤ N ≤ 100) representing the number of vertices in the tree. Vertices are identified by distinct integers from 11 to NN. Each of the next N−1N - 1 lines contains two integers UU and VV (1≤U,V≤N1 ≤ U, V ≤ N and U≠VU \ne V), indicating that the tree has the edge (U,V)(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_1T\_1 that is isomorphic to T_2T\_2, and the uppercase letter “N” otherwise.

예제3

  1. 예제 1

    입력
    5
    1 3
    4 5
    3 2
    3 4
    4
    2 4
    2 1
    3 2
    
    예상 출력
    Y
    
  2. 예제 2

    입력
    4
    2 3
    2 1
    2 4
    4
    1 2
    2 3
    3 4
    
    예상 출력
    N
    
  3. 예제 3

    입력
    1
    1
    
    예상 출력
    Y