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

33370번 - Anti-Plagiarism 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 2048 MB322222.222%

문제

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 $T_1$ to be copied from a tree $T_2$ if it is possible to add some (possibly zero) vertices and edges to $T_2$ and relabel its vertices so that it becomes the same as $T_1$.

In total, she suspects $t$ 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 $t$ (1ドル \le t \le 10^4$): the number of suspicious pairs of students.

After that, there are $t$ descriptions of pairs of trees.

The first line of each description contains an integer $n$ (2ドル \le n \le 10^5$). Each of the next $n-1$ lines contains two integers $u$ and $v$ (1ドル \le u, v \le n$): the edges of the first student's tree.

The next line of each description contains an integer $m$ (2ドル \le m \le n$). Each of the next $m-1$ lines contains two integers $u$ and $v$ (1ドル \le u, v \le m$): the edges of the second student's tree.

It is guaranteed that the sum of $n$ over all pairs of students does not exceed 5ドル \cdot 10^5,ドル and the sum of $n \cdot m$ does not exceed 10ドル^7$.

출력

For each of the $t$ 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.

제한

예제 입력 1

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

예제 출력 1

Yes
No

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2023 > Day 5: Moscow IPT Yolki-Palki Contest 1 A번

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

출처

대학교 대회

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

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