#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 farms (), numbered . The farms are connected by roads, such that every farm can be reached from farm by traveling along some roads.
Unfortunately, a cow on farm 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 . The next lines each contain two space-separated integers and , indicating a road between farms and . Both and are in the range .
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 doubles and then doubles again, so after days there are infected cows on farm . Over the next days, one infected cow travels from farm to farms , , and , respectively. After days, every farm has at least infected cow.
- In testdata 1–4, every farm (except farm ) is directly connected to farm .
- In testdata 5–7, each of farms 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
京公网安备 11011102002149号