#P5197. Minimal Grass Types

    ID: 18433 Type: Default 1000ms 256MiB

Minimal Grass Types

Minimal Grass Types

Farmer John has a farm with N fields (numbered from 1 to \(N\)) connected by \(N-1\) bidirectional roads such that any field is reachable from any other. He wants to plant grass in each field while minimizing the number of different grass types used, because using more types incurs higher costs.

However, his cows are very particular: if any two adjacent fields (directly connected by a road) are planted with the same type of grass or if any two fields that are both adjacent to a common field have the same type of grass, the cows will complain. In other words, if we consider the fields as vertices in a tree, then for every vertex, its color should be distinct from the color of all vertices directly connected to it, and moreover, all of its neighbors must have pairwise distinct colors.

Your task is to help Farmer John determine the minimum number of grass types required to satisfy these conditions.

Hint: It can be shown that the answer is \(\max_{1 \leq i \leq N}(\text{degree}(i)) + 1\), where \(\text{degree}(i)\) is the number of roads (neighbors) connected to field \(i\).

inputFormat

The first line contains a single integer \(N\) \((1 \leq N \leq 10^5)\), the number of fields.

The next \(N-1\) lines each contain two integers \(u\) and \(v\) denoting that there is a bidirectional road connecting field \(u\) and field \(v\).

outputFormat

Output a single integer representing the minimum number of grass types needed.

sample

1
1