PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#LCA0000078. Cây, CÂY! (Tree, TREE!!!)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Cây, CÂY! (Tree, TREE!!!)

Tree, TREE!!!

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given an undirected tree of nn vertices and integer kk. For each vertex rr used as root, consider all size-kk subsets of distinct vertices. Let f(r)f(r) be the number of distinct vertices that can be the LCA of at least one such subset when rooted at rr. Compute ∑r=1nf(r)\sum_{r=1}^{n} f(r). A vertex is its own ancestor. The same LCA vertex contributes only once for any fixed root.

Input

First line contains n kn\ k, followed by n−1n-1 edges u vu\ v.

Output

Print one integer: the sum of numbers of distinct possible LCA vertices over all roots.

Subtasks

General constraints: 2≤n≤2⋅1052\le n\le 2\cdot10^5; 2≤k≤n2\le k\le n; các cạnh tạo thành cây; kết quả dùng số nguyên 64 bit.

  • Subtask 1 (20 points): 1≤n≤401\le n\le 40.

  • Subtask 2 (30 points): 1≤n≤10001\le n\le 1000.

  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000.

Examples

Input

5 3
1 2
1 3
1 4
1 5

Output

9

Explanation

With root 11, only vertex 11 can be the LCA of three selected vertices. Rerooting at a leaf changes the possible LCA vertices. Summing across all five root choices gives 99.