Anti-Plagiarism
시간 제한5초메모리 제한2048 MB
각 트리 쌍마다 큰 트리가 작은 트리를 부분그래프로 포함하는지, 즉 부분트리 동형인지 판정한다.
문제
As a homework, the teacher asked all the students of the art class to draw a beautiful, and most importantly original, tree. After everyone has submitted their work, the teacher began to suspect some students of cheating.
The teacher considers a tree to be copied from a tree if it is possible to add some (possibly zero) vertices and edges to and relabel its vertices so that it becomes the same as .
In total, she suspects pairs of students. For each given pair of trees, check if first tree could be copied from the second tree.
입력
The first line contains an integer (): the number of suspicious pairs of students.
After that, there are descriptions of pairs of trees.
The first line of each description contains an integer (). Each of the next lines contains two integers and (): the edges of the first student's tree.
The next line of each description contains an integer (). Each of the next lines contains two integers and (): the edges of the second student's tree.
It is guaranteed that the sum of over all pairs of students does not exceed , and the sum of does not exceed .
출력
For each of the pairs of trees, print a line containing a single word (case-insensitive): "Yes" if the first tree could be copied from the second tree, or "No" otherwise.