1885Color the Tree

1885   Color the Tree

题目描述

Given a tree with n nodes (which are represented by numbers from 1 to n) and m colors. How many different ways are there to color the nodes so that none of two neighboring nodes have the same color?

输入格式:

There are several test cases.

For each test case, the first line contains two positive integers n (1 <= n <= 50) and m (2 <= m <= 20).

The next n-1 lines each gives the indices of two nodes that are connected by an edge and hence describe the structure of a tree.

The input is terminated with 0 0.

输出格式:

For each test case print in a single line the number of different coloring ways.

输入样例 复制
2 2
1 2
0 0
输出样例 复制
2

说明

2
2
通过提交
时空限制2000ms/64mb
题目来源ZOJ Monthly, February 2003
评测方式在线评测
题目类型
难        度