#abc293h. Ex - Optimal Path Decomposition

Ex - Optimal Path Decomposition

Score : 600600 points

问题描述

你给定一棵包含 NN 个顶点的树,顶点编号从 11NN。第 ii 条边连接顶点 AiA_i 和顶点 BiB_i

求一个最小整数 KK,使得你可以为每个顶点涂色,使得以下两个条件得到满足。你可以使用任意数量的颜色。

  • 对于每种颜色,该颜色涂过的顶点集合是连通的,并且构成一条简单路径。
  • 对于树上的所有简单路径,路径中的顶点颜色至多有 KK 种不同颜色。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a tree with NN vertices numbered 11 through NN. The ii-th edge connects vertex AiA_i and vertex BiB_i.

Find the minimum integer KK such that you can paint each vertex in a color so that the following two conditions are satisfied. You may use any number of colors.

  • For each color, the set of vertices painted in the color is connected and forms a simple path.
  • For all simple paths on the tree, there are at most KK distinct colors of the vertices in the path.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1Ai,BiN1 \leq A_i, B_i \leq N
  • The given graph is a tree.
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN

A1A_1 B1B_1

\vdots

AN1A_{N-1} BN1B_{N-1}

Output

Print the answer.

Sample Input 1

7
3 4
1 5
4 5
1 2
7 4
1 6

Sample Output 1

3

If K=3K=3, the conditions can be satisfied by painting vertices 1,2,3,41,2,3,4, and 55 in color 11, vertex 66 in color 22, and vertex 77 in color 33. If K2K \leq 2, there is no way to paint the vertices to satisfy the conditions, so the answer is 33.

Sample Input 2

6
3 5
6 4
6 3
4 2
1 5

Sample Output 2

1

Sample Input 3

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

Sample Output 3

3

update @ 2024/3/10 12:13:13