#C6888. Maximum Communicating Servers

    ID: 50697 Type: Default 1000ms 256MiB

Maximum Communicating Servers

Maximum Communicating Servers

You are given a network of n servers connected as a tree with n - 1 bidirectional edges. The master server is labeled 1. Exactly k servers are taken offline for maintenance. When a server is offline, it cannot communicate with any other server. Your task is to determine the maximum number of servers that can still communicate with the master server after taking exactly k servers offline.

The offline servers are chosen as the k servers farthest from the master server (when measured by the shortest path distance). If multiple servers have the same distance, the selection is made arbitrarily from those servers.

Input Format: The first line contains two integers n and k. The following n - 1 lines each contain two integers u and v denoting an edge between servers u and v.

Output Format: A single integer denoting the maximum number of servers (including the master) that remain connected to the master server.

inputFormat

The input is given via standard input (stdin) with the following format:

  1. The first line contains two space-separated integers: n (the number of servers) and k (the number of servers to take offline).
  2. The next n - 1 lines each contain two space-separated integers u and v which indicate that there is an edge between servers u and v.

outputFormat

Output a single integer via standard output (stdout) which is the maximum number of servers that remain connected to the master server.

## sample
7 3
1 2
2 3
3 4
4 5
3 6
6 7
4