VK Cup 2017 - Round 1
C
Bear and Tree Jumps
Codeforces
2100
原题
← BD →
翻译中…

A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them.

翻译中…

Limak is a little polar bear. He lives in a tree that consists of $*n*$ vertices, numbered $1$ through $*n*$.

翻译中…

Limak recently learned how to jump. He can jump from a vertex to any vertex within distance at most $*k*$.

翻译中…

For a pair of vertices $(*s*, *t*)$ we define $*f*(*s*, *t*)$ as the minimum number of jumps Limak needs to get from $*s*$ to $*t*$. Your task is to find the sum of $*f*(*s*, *t*)$ over all pairs of vertices $(*s*, *t*)$ such that $*s* < *t*$.

翻译中…

Input

翻译中…

The first line of the input contains two integers $*n*$ and $*k*$ ($2 ≤ *n* ≤ 200 000$, $1 ≤ *k* ≤ 5$) — the number of vertices in the tree and the maximum allowed jump distance respectively.

翻译中…

The next $*n* - 1$ lines describe edges in the tree. The $*i*$-th of those lines contains two integers $*a*_{*i*}$ and $*b*_{*i*}$ ($1 ≤ *a*_{*i*}, *b*_{*i*} ≤ *n*$) — the indices on vertices connected with $*i*$-th edge.

翻译中…

It's guaranteed that the given edges form a tree.

翻译中…

Output

翻译中…

Print one integer, denoting the sum of $*f*(*s*, *t*)$ over all pairs of vertices $(*s*, *t*)$ such that $*s* < *t*$.

翻译中…

Note

翻译中…

In the first sample, the given tree has $6$ vertices and it's displayed on the drawing below. Limak can jump to any vertex within distance at most $2$. For example, from the vertex $5$ he can jump to any of vertices: $1$, $2$ and $4$ (well, he can also jump to the vertex $5$ itself).

翻译中…

image

翻译中…

There are image pairs of vertices $(*s*, *t*)$ such that $*s* < *t*$. For $5$ of those pairs Limak would need two jumps: $(1, 6), (3, 4), (3, 5), (3, 6), (5, 6)$. For other $10$ pairs one jump is enough. So, the answer is $5·2 + 10·1 = 20$.

翻译中…

In the third sample, Limak can jump between every two vertices directly. There are $3$ pairs of vertices $(*s* < *t*)$, so the answer is $3·1 = 3$.

翻译中…

样例

Input #1
6 2
1 2
1 3
2 4
2 5
4 6
Output #1
20
InputCopy OutputCopy
Input #2
13 3
1 2
3 2
4 2
5 2
3 6
10 6
6 7
6 13
5 8
5 9
9 11
11 12
Output #2
114
InputCopy OutputCopy
Input #3
3 5
2 1
3 1
Output #3
3
InputCopy OutputCopy
题目信息
题号
771C
时间限制
2 s
内存限制
256 MB
标签
DFS 及类似
动态规划
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。