#P3441. Subway Route Planning

    ID: 16696 Type: Default 1000ms 256MiB

Subway Route Planning

Subway Route Planning

A certain city has been coping with subway construction for a long time. Due to poor budgeting, only a tree has been built – that is, there are n stations and n-1 bidirectional tunnels (so that there is a unique path between any two stations). In addition, only l trains have been acquired. In order to save face, the directors have asked you to plan subway routes for the trains so that the union of stations visited (i.e. covered) by these routes is maximized.

Each train runs on a fixed route, which is a simple (nonbranching) path in the tree. (Formally, a route is defined as a sequence of stations \(v_1, v_2, \dots, v_k\) such that for every \(1 \le i < k\) there is a tunnel between \(v_i\) and \(v_{i+1}\); note that the routes do not need to be vertex‐disjoint.)

Your task is to compute the maximum number of stations that can be covered by l such routes.

Note: A station is considered covered if it occurs in at least one of the chosen routes.

inputFormat

The input is given from standard input and has the following format:

n l
u1 v1
u2 v2
... 
un-1 vn-1

Here, n is the number of stations, l is the number of subway routes (i.e. paths) to choose. Each of the next n-1 lines contains two integers \(u_i\) and \(v_i\) (1-indexed) meaning that there is a bidirectional tunnel between these two stations. It is guaranteed that the tunnels form a tree, i.e. there is exactly one unique simple path between any two stations.

outputFormat

Output a single integer — the maximum number of stations which can be covered by at most l subway routes.

sample

4 1
1 2
2 3
2 4
3