#P2996. [USACO10NOV] Visiting Cows G
[USACO10NOV] Visiting Cows G
Description
After many weeks of hard work, Bessie is finally getting a vacation. She wants to visit friends, labeled . The cows have set up an unusual road network with exactly roads connecting pairs of cows and (, , ), so that there is a unique path between any two cows.
FJ wants Bessie to come back to the farm soon; therefore, if two cows are directly connected by a road, she may not visit both. Bessie would like her vacation to be as long as possible, so she wants to determine the maximum number of cows she can visit.
Constraints: .
Input Format
- Line 1: A single integer .
- Lines 2..: Each line describes one road with two space-separated integers: and .
Output Format
- Line 1: A single integer representing the maximum number of cows that Bessie can visit.
7
6 2
3 4
2 3
1 2
7 6
5 6
4
Hint
Bessie knows cows. The roads form the following tree:
1--2--3--4
|
5--6--7
Bessie can visit four cows. The best combinations include two cows on the top row and two on the bottom. She cannot visit cow 6 since that would prevent visiting cows 5 and 7; thus she visits 5 and 7. She can also visit two cows on the top row: , , or .
京公网安备 11011102002149号