Favorite Tree

아직 제출이 없습니다시간 제한0.1초메모리 제한1024 MB

문제

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 (1N1001 ≤ N ≤ 100) representing the number of vertices in the tree. Vertices are identified by distinct integers from 11 to NN. Each of the next N1N - 1 lines contains two integers UU and VV (1U,VN1 ≤ U, V ≤ N and UVU \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.