Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
hackercup / 2013 /finals /colored_trees.html
wjomlex's picture
2013 Problems
c623d8c verified
raw
history blame
1.42 kB
<p>You are given two integers <strong>N</strong> and <strong>K</strong>, 1 &le; <strong>N</strong> &le; 1000, 1 &le; <strong>K</strong> &le; 10<sup>9</sup>.
Your task is to calculate how many distinct trees with <strong>N</strong> vertices there are with each vertex colored with one of <strong>K</strong> colors. Multiple vertices can have the same color, and not all colors need to be used. Two trees t1 and t2 are considered identical if there exists a
bijective function f from vertices of t1 to vertices of t2 such that each vertex
x in t1 is colored the same as f(x) in t2 and each pair of
vertices x, y in t1 is connected by an edge if and only if f(x) and f(y) are
connected by an edge in t2. A bijective function is a function that is both one-to-one and onto, meaning that f(x) = f(y) if and only if x = y, and for every vertex y in t2, there exists x in t1, such that f(x) = y.</p>
<h2>Input</h2>
<p>The first line contains a single integer <strong>T</strong>, <strong>T</strong> &le; 20. <strong>T</strong> test cases follow, where each test case consists of two integers: <strong>N</strong> and <strong>K</strong>.</p>
<h2>Output</h2>
<p>Output one single line with the number of colored trees.
Since this number might be very big, output it modulo <strong>1,000,000,007</strong>.</p>
<h2>Examples</h2>
<img src="https://fbcdn-dragon-a.akamaihd.net/cfs-ak-ash3/676523/506/293813004081038_-/tmp-/IV3SsS" />