Grass Planting
Time limit2sMemory limit512 MB
Given a tree with N fields, plant grass so that no two fields at distance one or two share a type, and output the minimum number of types needed.
Problem
It is the time of year for Farmer John to plant grass in all of his fields. The farm consists of fields (), numbered , and connected by bidirectional pathways so that every field can reach every other field by following some collection of pathways.
Farmer John could plant a different type of grass in each field, but he wants to minimize the total number of grass types he uses, since using more types of grass costs more.
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 by pathways to a common field), the cows will complain about a lack of variety in their dining options. The last thing Farmer John needs is complaining cows, given how much mischief they cause when dissatisfied.
Help Farmer John determine the minimum number of grass types he needs for the whole farm.
Input
The first line of input contains . Each of the remaining lines describes a pathway by the two fields it connects.
Output
Print the minimum number of grass types that Farmer John needs to use.
Notes
In this simple example there are 4 fields connected in a line. At least three grass types are needed. For instance, Farmer John could plant the fields with grass types A, B, and C as A - B - C - A.