Problem F
Rainbow Trees
In graph theory, a tree is a connected, undirected
simple graph with no cycles. A tree with
A path in a tree is a sequence of distinct edges which are connected (each pair of consecutive edges in the path share a vertex).
Consider a tree with
An assignment of colors to edges is a rainbow coloring if in every path of 2 or 3 edges, the colors of the edges are different. (i.e., every two consecutive edges have different colors, and every three consecutive edges have different colors).
Given a tree and the number of colors
Input
The first line of input gives the number of test cases,
-
One line containing two integers
and , where is the number of nodes in the tree, and is the number of colors available. -
lines, one for each edge, containing two integers , indicating that the edge is between node and node . Nodes are numbered from 1 to .
You may assume that
Output
For each test case, output one line. That line should
contain "Case #
Sample Input 1 | Sample Output 1 |
---|---|
2 4 10 1 2 1 3 1 4 5 3 1 2 2 3 3 4 4 5 |
Case #1: 720 Case #2: 6 |