#P7148. [USACO20DEC] Cowntagion S

[USACO20DEC] Cowntagion S

Description

Farmer John and his team of farmers have been working day and night to control the spread of the cow infectious disease COWVID-19 among their farms.

They are monitoring a total of NN farms (1N1051 \le N \le 10^5), numbered 1N1 \ldots N. The farms are connected by N1N - 1 roads, such that every farm can be reached from farm 11 by traveling along some roads.

Unfortunately, a cow on farm 11 has tested positive for COWVID-19. For now, the other cows on this farm, as well as all cows on all other farms, are not infected yet. However, based on the fact that this disease spreads through contact, Farmer John predicts that each day, one of the following unfortunate events will happen:

(1) Within a farm, a “super spreader” causes the number of cows infected with COWVID-19 on that farm to double; or

(2) One cow infected with COWVID-19 travels from one farm to an adjacent farm along a road.

Farmer John is worried that the outbreak will quickly get out of control. Please help Farmer John compute the minimum number of days required until every farm has at least one infected cow.

Input Format

The first line of input contains an integer NN. The next N1N - 1 lines each contain two space-separated integers aa and bb, indicating a road between farms aa and bb. Both aa and bb are in the range 1N1 \ldots N.

Output Format

Output the minimum number of days required for the outbreak to reach all farms.

4
1 2
1 3
1 4
5

Hint

One possible sequence of events for the sample is as follows. The number of infected cows on farm 11 doubles and then doubles again, so after 22 days there are 44 infected cows on farm 11. Over the next 33 days, one infected cow travels from farm 11 to farms 22, 33, and 44, respectively. After 55 days, every farm has at least 11 infected cow.

  • In testdata 1–4, every farm (except farm 11) is directly connected to farm 11.
  • In testdata 5–7, each of farms 2N2 \ldots N is connected to at most two roads.
  • In testdata 8–15, there are no additional constraints.

Problem provided by: Dhruv Rohatgi.

Translated by ChatGPT 5