Symmetric Trees (Small)
Time limit5sMemory limit512 MB
Decide whether a colored tree with at most 12 vertices admits a planar straight-line drawing with a vertical line of symmetry.
- Level
Medium6 of 10
- Topics
- Brute force, Tree, Backtracking
- Solved
- No attempts yet
Problem
You are given a tree with vertices, and each vertex has a color. Decide whether the tree can be drawn in the plane so that it has a line of symmetry.
Formally, a tree is line symmetric if every vertex can be assigned a location in the plane so that all four conditions below hold at once.
- No two vertices share a location.
- If vertex has color and location , then a vertex with color and location also exists. If is , then and are the same vertex.
- If edge exists, then edge also exists.
- When each edge is drawn as the straight segment between its two endpoints, two different segments share no point except an endpoint shared by two adjacent edges.
Input
The first line contains the number of test cases . The test cases follow.
The first line of each test case contains the number of vertices in the tree.
The next lines each contain one uppercase letter. The -th of these lines is the color of vertex .
The next lines each contain two integers and (). This means the tree has an edge between vertex and vertex . The given edges always form a connected tree.
Limits
Output
For each test case, print one line in the form "Case #x: y", where is the test case number starting from , and is SYMMETRIC if the tree is line symmetric by the definition above and NOT SYMMETRIC otherwise.
Hint
The first test case can be drawn like this.

No placement of the vertices of the second test case gives a line of symmetry.

One way to draw the third test case with a line of symmetry is shown below.
