#P14740. [ICPC 2021 Seoul R] Logistical Warehouse 2

[ICPC 2021 Seoul R] Logistical Warehouse 2

题目描述

KOPANG is one of largest online vendors in Korea and introduced so called "early-morning delivery" for the first time. To cope with the growing demand, KOPANG plans to build new logistical warehouses. The locations of logistical warehouses must be within a certain distance from customers to keep the delivery time guaranteed by KOPANG to the customers.

The logistics network is modelled as a connected tree TT. Each node of TT represents a region such as a city or a province in Korea, and each edge of TT represents a transportation road connecting two regions. KOPANG wants to select one or more nodes of TT satisfying the distance restriction for the logistical warehouses. Before the selection, KOPANG first fixed a distance parameter KK through sufficient research. KOPANG now wants to select the minimum number of nodes satisfying the distance restriction that the distance from every node of TT to its closest selected node (warehouse) is at most KK. The distance of two nodes uu and vv is the number of edges of the (unique) path in TT that connects uu and vv. Note that the distance is defined as zero if u=vu = v.

For example, Figure G.1 below shows a tree TT with nine nodes and eight edges. For K=1K = 1, if three warehouses are located at nodes 2, 5, and 8, marked with red circles as in Figure G.1 (a), then the distance of every node of TT to the closest warehouse is at most one. Two warehouses are not enough to satisfy the distance restriction, so three warehouses are the minimum. For K=2K = 2, three warehouses are still required; warehouses at nodes 2, 5, and 8 for K=1K = 1 are the ones for K=2K = 2. Of course, the locations of the minimum number of warehouses are not unique; three warehouses at nodes 4, 7, and 1 as in Figure G.1 (b) also satisfy the distance restriction for K=2K = 2.

Given a connected tree TT and a positive integer KK, write a program to select the minimum number of nodes (warehouses) of TT satisfying the distance restriction, that is, the distance of every node of TT to its closest warehouse is at most KK.

:::align{center}

Figure G.1 The nodes marked with red circles are the ones selected for warehouses. :::

输入格式

Your program is to read from standard input. The input starts with a line containing two integers nn and KK (1Kn1051 \le K \le n \le 10^5), where nn is the number of nodes in a connected tree and the maximum distance from each node in the tree to its closest selected node is at most KK. In the following n1n-1 lines, the edge information is given; the ii-th line contains two positive integers representing two indices of the end nodes of the ii-th edge. The nodes are indexed from 1 to nn.

输出格式

Your program is to write to standard output. Print exactly one line that contains the minimum number of the selected nodes for logistical warehouses satisfying the distance restriction for the given tree and the distance parameter KK.

9 1
2 1
7 3
3 4
4 5
6 5
7 8
3 2
8 9
3
9 2
2 1
7 3
3 4
4 5
6 5
7 8
3 2
8 9
3
9 8
2 1
7 3
3 4
4 5
6 5
7 8
3 2
8 9
1