| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 0.1 초 | 1024 MB | 74 | 39 | 34 | 54.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.
5 1 3 4 5 3 2 3 4 4 2 4 2 1 3 2
Y
4 2 3 2 1 2 4 4 1 2 2 3 3 4
N
1 1
Y