Art Plagiarism

Xem dạng PDF

Gửi bài giải

Điểm: 1,36 (OI)
Giới hạn thời gian: 1.0s
Giới hạn bộ nhớ: 256M
Input: stdin
Output: stdout

Nguồn bài:
Google Code Jam - ACM Vietnam Practice
Dạng bài
Ngôn ngữ cho phép
C, C++, Go, Java, Kotlin, Pascal, PyPy, Python, Rust, Scratch

You have pictures of two sculptures. The sculptures consist of several solid metal spheres, and some rubber pipes connecting pairs of spheres. The pipes in each sculpture are connected in such a way that for any pair of spheres, there is exactly one path following a series of pipes (without repeating any) between those two spheres. All the spheres have the same radius, and all the pipes have the same length.

You suspect that the smaller of the two sculptures was actually created by simply removing some spheres and pipes from the larger one. You want to write a program to test if this is possible.

The input will contain several test cases. One sculpture is described by numbering the spheres

consecutively from ~1~, and listing the pairs of spheres which are connected by pipes. The

numbering is chosen independently for each sculpture.

Input

One line containing an integer ~C~, the number of test cases in the input file.

For each test case, there will be:

  • One line containing the integer ~N~, the number of spheres in the large sculpture.
  • ~N−1~ lines, each containing a pair of space-separated integers, indicating that the two spheres with those numbers in the large sculpture are connected by a pipe.
  • One line containing the integer ~M~, the number of spheres in the small sculpture.
  • ~M−1~ lines, each containing a pair of space-separated integers, indicating that the two spheres with those numbers in the small sculpture are connected by a pipe.

Output

~C~ lines, one for each test case in the order they occur in the input file, containing:

  • "Case #X: YES" if the small sculpture in case ~X~ could have been created from the large sculpture in case ~X~
  • "Case #X: NO" if it could not. ~(X~ is the number of the test case, between ~1~ and ~C~.)

Giới hạn

~1 \le C \le 50~

~2 \le N \le 50~

~1 \le M \le N~

Sample Input

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

Sample Output

Case #1: NO
Case #2: YES

Bình luận

Hãy đọc nội quy trước khi bình luận.



  • 0
    Khanhcsp2  đã bình luận lúc 22, Tháng 11, 2023, 15:00

    Bai kho qua - sieu tri tue!


  • 0
    cbl_nhat  đã bình luận lúc 11, Tháng 5, 2022, 12:58

    giới hạn n <= 100 nha mọi người