8006: Grass Planting

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:92 通过:44

题目描述

到了一年中Farmer John在他的草地里种草的时间了。整个农场由N块草地组成(1≤N≤105),方便起见编号为1…N,由N−1条双向的小路连接,每块草地都可以经过一些小路到达其他所有的草地。

Farmer John当然可以在每块草地里种不同种类的草,但是他想要使得使用的草的种类数最小,因为他用的草的种类数越多,他就需要负担更高的花费。

不幸的是,他的奶牛们对选择农场上的草表现得十分苛刻。如果两块相邻(由一条小路直接相连)的草地种了同一种草,或者即使是两块接近相邻(均可由一条小路直接连向同一块草地)的草地,那么奶牛们就会抱怨她们进餐的选择不够多样。Farmer John能做的只能是抱怨这些奶牛,因为他知道她们不能被满足的时候会制造多大的麻烦。

请帮助Farmer John求出他的整个农场所需要的最少的草的种类数。

输入格式(文件名:planting.in):

输入的第一行包含N。以下N−1行每行描述了一条小路连接的两块草地。

输出格式(文件名:planting.out):

输出Farmer John需要使用的最少的草的种类数。

输入样例:

4
1 2
4 3
2 3

输出样例:

3

在这个简单的例子中,4块草地以一条直线的形式相连。最少需要三种草。例如,Farmer John可以用草A,B和C将草地按A - B - C - A的方式播种。




It's the time of year for Farmer John to plant grass in all of his fields. The entire farm consists of N fields (1≤N≤105), conveniently numbered 1…N and conveniently connected by N−1 bidirectional pathways in such a way that every field can reach every other field via some collection of pathways.

Farmer John can potentially plant a different type of grass in each field, but he wants to minimize the number of grass types he uses in total, since the more types of grass he uses, the more expense he incurs.

Unfortunately, his cows have grown rather snobbish about their selection of grass on the farm. If the same grass type is planted in two adjacent fields (directly connected by a pathway) or even two nearly-adjacent fields (both directly connected to a common field with pathways), then the cows will complain about lack of variety in their dining options. The last thing Farmer John needs is complaining cows, given how much mischief they have been known to create when dissatisfied.

Please help Farmer John determine the minimum number of types of grass he needs for his entire farm.

INPUT FORMAT (file planting.in):

The first line of input contains N. Each of the remaining N−1 lines describes a pathway in terms of the two fields it connects.

OUTPUT FORMAT (file planting.out):

Print the minimum number of types of grass that Farmer John needs to use.

SAMPLE INPUT:

4
1 2
4 3
2 3

SAMPLE OUTPUT:

3

In this simple example, there are 4 fields all connected in a linear fashion. A minimum of three grass types are needed. For example, Farmer John could plant the fields with grass types A, B, and C as A - B - C - A.

输入样例 复制

4
1 2
4 3
2 3

输出样例 复制

3