#P2977. [USACO10JAN] Cow Telephones G

[USACO10JAN] Cow Telephones G

Description

The cows have set up a telephone network, which for the purposes of this problem can be considered to be an unrooted tree of unspecified degree with NN (1N100,0001 \le N \le 100{,}000) vertices conveniently numbered 1N1\dots N. Each vertex represents a telephone switchboard, and each edge represents a telephone wire between two switchboards. Edge ii is specified by two integers AiA_i and BiB_i the are the two vertices joined by edge ii (1AiN1 \le A_i \le N; 1BiN1 \le B_i \le N; AiBiA_i \ne B_i).

Some switchboards have only one telephone wire connecting them to another switchboard; these are the leaves of the tree, each of which is a telephone booth located in a cow field.

For two cows to communicate, their conversation passes along the unique shortest path between the two vertices where the cows are located. A switchboard can accomodate only up to KK (1K101 \le K \le 10) simultaneous conversations, and there can be at most one conversation going through a given wire at any one time.

Given that there is a cow at each leaf of the tree, what is the maximum number of pairs of cows that can simultaneously hold conversations? A cow can, of course, participate in at most one conversation.

Input Format

* Line 11: Two space separated integers: NN and KK.

* Lines 2N2\dots N: Line i+1i+1 contains two space-separated integers: AiA_i and BiB_i.

Output Format

* Line 11: The number of pairs of cows that can simultaneously hold conversations.

6 1 
1 2 
2 3 
2 4 
4 5 
4 6 

2 

Hint

1   5          C1   C5 
|   |          ||   || 
2---4   -->    |2---4| 
|   |          ||   || 
3   6          C3   C6 

Consider this six-node telephone tree with K=1K=1:

There are four cows, located at vertices 11, 33, 55 and 66. If cow 11 talks to cow 33, and cow 55 talks to cow 66, then they do not exceed the maximum number of conversations per switchboard, so for this example the answer is 22 (for two pairs of cows talking simultaneously).