Beauty of Programming

Source: Internet
Author: User


Question 1: homogeneous time limit: 256 ms single point time limit: Ms memory limit: MB

Description

Given two trees A and B, ensure that the number of nodes of A is greater than or equal to the number of nodes of B.

Now you need to perform two dyeing on the side of tree.

A good dyeing scheme means that the connected block in tree A does not exist and meets the following two conditions at the same time.

1. There are only edges of the same color.

2. homogeneous with B. A one-to-one ing (single-shot and full-shot) exists between two trees to map each node of Tree B to A node of different tree, so that the adjacent points in Tree B are still adjacent after ing.

Ask if there is a good dyeing solution.


Input

The first line is an integer T (1 <=t <= 10), indicating the number of data groups.

Next, there is no blank line between the input data of the T group and the test data.


The data format of each group is as follows:

The first line is an integer N, indicating the total number of nodes in tree.

Next, for the N-1 row, each row has two numbers a, B (1 <= a, B <= N), indicating that there is an edge between node A and Node B of tree.

In the next row, an integer M (1 <= M <= N) indicates the total number of nodes in Tree B.

Next, for the M-1 row, each row has two numbers a, B (1 <= a, B <= M), indicating that there is an edge between node a and Node B of Tree B.


Output

For each group of data, "Case x:" Is output first, and "x" indicates the group of data. Then, "YES"/"NO" is output, indicating whether a dyeing scheme is required.


Data range

Small Data: 1 <= N <= 20

Big Data: 1 <= N <= 1000000


Example

No matter how you dye it, you just need to pick an edge from.


Sample Input
131 22 321 2
Sample output
Case 1: NO

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.