A tree is a connected graph with no cycles.
A rooted tree is a tree in which one special vertex is called the root. If there is an edge between
A full binary tree is a rooted tree where every node has either exactly 2 children or 0 children.
You are given a tree
Input Specification
The first line of the input gives the number of test cases,
Output Specification
For each test case, output one line containing Case #x: y
, where
Limits
Memory limit: 1 GB.
Each test case will form a valid connected tree.
Small Dataset
Time limit: 60 seconds.
Large Dataset
Time limit: 120 seconds.
Sample Input
3
3
2 1
1 3
7
4 5
4 2
1 2
3 1
6 4
3 7
4
1 2
2 3
3 4
Sample Output
Case #1: 0
Case #2: 2
Case #3: 1
In the first case,
In the second case, we may delete nodes 3 and 7; then 2 can be the root of a full binary tree.
In the third case, we may delete node 1; then 3 will become the root of a full binary tree (we could also have deleted node 4; then we could have made 2 the root).
Note
This problem has different time limits for different batches. If you exceed the Time Limit for any batch, the judge will incorrectly display >120.000s
regardless of the actual time taken. Refer to the Limits section for batch-specific time limits.
Comments