Decide whether the smaller tree is a connected subgraph of the larger tree, with only the shapes mattering, not the original labels.
Easy3TreeBacktrackingInterviewNo attempts yetTime limit5sMemory limit512 MBYou have photographs of two sculptures. A sculpture is made of solid metal spheres and rubber pipes, where each pipe joins two spheres. The pipes are arranged so that for any two spheres there is exactly one route between them that never uses the same pipe twice. Every sphere has the same radius and every pipe has the same length.
You suspect that the smaller of the two sculptures was made by removing some spheres and some pipes from the larger one. Write a program that decides whether that is possible.
A sculpture is described by numbering its spheres from 1 upward and listing the pairs of spheres joined by a pipe. The numbering is chosen separately for each sculpture, so the same number does not refer to the same sphere in both. The input contains several test cases.
The first line contains the number of test cases C.
Each test case is given in this order.
Limits
Print C lines, one per test case, in the order the test cases appear in the input. For test case X, print Case #X: YES if the small sculpture could have been made from the large one, or Case #X: NO if it could not. Here X is the number of the test case, from 1 to C.
In the first test case of the sample the large sculpture is five spheres in a single line, and the small sculpture is one sphere with three other spheres attached to it. Nothing you remove from the large sculpture produces the small one.
In the second test case the small sculpture is four spheres in a single line. Matching them to spheres 2, 1, 4, 5 of the large sculpture in that order works.