MKLABELS - Making Labels

Trees comes in many varieties other than the popular binary tree. In general, a tree is a connected acyclic graph. That is, it consists of some number of vertices N (which we’ll assume is at least one in this problem), and N – 1 edges, each of which connects a pair of vertices.

A “labeled tree” is a tree in which each vertex has been given a “label.” For simplicity, let us assume these labels are the integers 1 through N. In how many different ways may a tree with N vertices be labeled? By “different” we mean that no rearrangement of two trees with the same number of vertices with different labeling will be identical. (Note that although we commonly associate data with each vertex, and identify one vertex as the root of the tree, that’s not significant in this problem.)

Let’s consider some examples. The figure below shows all possible arrangements of trees with N = 1, 2, 3, 4, or 5 vertices. The number shown below each tree is the number of different ways in which the vertices in each tree can be labeled.

Illustration

Clearly a tree with only one vertex can be labeled in only one way – by assigning the label “1” to the single vertex. A tree with two vertices can also be labeled in only one way. For example, although the two trees shown on the left below appear to be different, the first can be easily transformed into the second. (Imagine the edges are strings, so the vertices can be easily repositioned without losing their connectivity.)

Illustration

There are, however, three possible ways to label the vertices in a 3-vertex tree, as shown on the right above. No matter how you rearrange the labeled vertices in any of the three trees, you cannot produce any of the other labeled trees.

In a similar manner, the various arrangements of four vertices in a tree yield a total of 16 possible labelings – 12 for the four vertices “in a row,” and 4 for the other configuration. There are three possible arrangements of the vertices in a tree with N = 5, with a total of 125 possible

Input

There will be multiple cases to consider. The input for each case is an integer N specifying the number of vertices in a tree, which will always be between 1 and 10. The last case will be followed by a zero.

Output

For each input case, display the case number (1, 2, …), the input value of N, and the number of different ways in which a tree with N vertices may be labeled. Use the format shown in the examples below.

Example

Input:
2
3
4
5
0

Output:
Case 1, N = 2, # of different labelings = 1
Case 2, N = 3, # of different labelings = 3
Case 3, N = 4, # of different labelings = 16
Case 4, N = 5, # of different labelings = 125

Added by:Camilo Andrés Varela León
Date:2007-10-07
Time limit:0.100s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:North Central North America Regional Programming Contest - 2003

hide comments
2016-01-01 19:22:02 Arnab Animesh Das
If you are getting WA, even after typing correctly, then check with 9 and 10 as input.
2015-11-19 16:01:26 Ray Brish Bhanu
my 50th...be careful about pow function...;)
2015-09-28 13:55:41
didn't even read the question..jst see the test cases and hit the pattern..!!
2015-09-22 19:15:46 surya kiran
Beware of spaces
2015-08-28 01:41:42
I have no idea what this question is looking for, but the pattern lol.. AC

Last edit: 2015-08-28 01:42:06
2015-08-19 18:49:46 Shivam Singh
don't even look at the problem statement, just looking at the test cases will give you the answer
2015-06-05 08:04:34 Harshit
just observe the test cases.
2015-05-13 03:05:28 :.Mohib.:
Easiest on spoj..... :)
2015-02-09 20:48:13 Raj Kumar Chauhan
easy ques, unusual spaces in output caused me 2 WA :(
do care of it.
2014-12-29 19:38:47 agaurav77
This question is more about "how well can you construct a solution based on the pattern you see in the test cases" rather than "come on, do the math". :D
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.