P28663 [洛谷] [CQOI2017] Xiao Q's Chessboard
提高
题目描述

Problem Description

Xiao Q is designing a board game.

In Xiao Q's game, pieces can be placed on the lattice points of the board. Certain lattice points are connected by lines, and pieces can only move between lattice points connected by lines. The entire board has $V$ lattice points, numbered from $0$ to $V-1$, and they are all connected, meaning a piece can reach any lattice point starting from any point. Xiao Q ensures that the path for a piece to move from one lattice point to any other is unique.

Xiao Q now wants to know, starting from lattice point $0$ and moving $N$ steps, what is the maximum number of distinct lattice points that can be traversed. A lattice point can be visited multiple times but is only counted once.

Input Format

The first line contains two positive integers $V$ and $N$, where $V$ represents the total number of lattice points and $N$ represents the number of moves.

The next $V-1$ lines each contain two numbers $a_i$ and $b_i$, indicating that the lattice points numbered $a_i$ and $b_i$ are connected by a line.

Output Format

Output a single integer, which is the maximum number of distinct lattice points that can be traversed.

Sample Input and Output

Sample Input #1

5 2
1 0
2 1
3 2
4 3

Sample Output #1

3

Sample Input #2

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

Sample Output #2

5

Notes

Sample 1 Explanation:

Starting from lattice point $0$ and moving $2$ steps, the piece can traverse the points $0, 1, 2$, totaling $3$ distinct points.

Sample 2 Explanation:

One possible path is $0 \to 1 \to 3 \to 5 \to 3 \to 7$, traversing the points $0, 1, 3, 5, 7$, totaling $5$ distinct points.

Data Constraints:

For $100\%$ of the test cases, $1 \le N, V \le 100$, and $0 \le a_i, b_i < V$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 2 1 0 2 1 3 2 4 3
样例输出
3