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