#P3698. [CQOI2017] 小Q的棋盘

    ID: 1271 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划,dp贪心2017重庆各省省选枚举,暴力背包连通块

[CQOI2017] 小Q的棋盘

Description

Xiao Q is designing a board game.

In the game he designed, pieces can be placed on the grid points on the board. Some pairs of grid points are connected by lines, and a piece may move only between grid points that are connected by a line. There are VV grid points in total, labeled 0,1,2,,V10, 1, 2, \cdots, V - 1, and they are connected; that is, starting from any grid point, the piece can reach all grid points. Xiao Q also guarantees that the path between any two grid points is unique.

Xiao Q now wants to know: starting from grid point 00, after moving NN steps, what is the maximum number of grid points that can be visited? A grid point may be visited multiple times, but is counted only once.

Input Format

The first line contains 22 positive integers V,NV, N, where VV is the total number of grid points and NN is the number of moves.

Each of the next V1V - 1 lines contains two integers ai,bia_i, b_i, indicating that there is a line connecting grid points aia_i and bib_i.

Output Format

Output a single integer, the maximum number of grid points that can be visited.

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

Hint

[Explanation for Sample 1]

From grid point 00, move 22 steps. The piece visits 0,1,20, 1, 2, i.e., 33 grid points.

[Explanation for Sample 2]

One feasible path is 0135370 \to 1 \to 3 \to 5 \to 3 \to 7, visiting 0,1,3,5,70, 1, 3, 5, 7, i.e., 55 grid points.

Constraints

For 100%100\% of the testdata, 1N,V1001 \le N, V \le 100, and 0ai,bi<V0 \le a_i, b_i < V.

Translated by ChatGPT 5