luogu#P4827. [集训队互测 2011] Crash 的文明世界

    ID: 3858 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>动态规划 DP数学2011集训队互测组合数学二项式定理容斥原理Stirling 数

[集训队互测 2011] Crash 的文明世界

Problem Description

Crash has recently become obsessed with a game called Civilization V. In this game, players can build and develop their own countries, communicate with other countries through diplomacy, or conquer them through war.

Now Crash already owns a country with nn cities. These cities are connected by roads. Since building roads costs money, Crash only built n1n-1 roads to connect these cities, but it is guaranteed that there is a path between any two cities.

In the game, Crash needs to choose one city as the capital of his country. Choosing the capital requires considering many indicators, and one of them is:

S(i)=j=1ndist(i,j)kS(i) = \sum_{j = 1}^{n}{\rm dist}(i, j) ^ k

Here, S(i)S(i) denotes the indicator value of the ii-th city, dist(i,j){\rm dist}(i, j) is the minimum number of roads that must be traveled from city ii to city jj, and kk is a constant positive integer.

So Crash gives you a simple task: given the roads between the cities, for each city output its indicator value. Since the value may be very large, you only need to output it mod 10007\bmod\ 10007.

Input Format

The first line contains two positive integers nn and kk.

Then there are n1n-1 lines. Each line contains two positive integers u,vu, v (1u,vn1\le u, v\le n), indicating that there is a road connecting city uu and city vv. These roads are guaranteed to satisfy the requirements of the problem.

Output Format

Output nn lines in total, each with one positive integer. The integer on the ii-th line represents the indicator value of the ii-th city mod 10007\bmod\ 10007.

5 2
1 2
1 3
2 4
2 5

10
7
23
18
18

Hint

For 20%20\% of the testdata, n5000n\le 5000, k30k\le 30.

For 50%50\% of the testdata, n5×104n\le 5\times 10^4, k30k\le 30.

For 100%100\% of the testdata, 1n5×1041\le n\le 5\times 10^4, 1k1501\le k\le 150.

Translated by ChatGPT 5