Cowntagion
Farmer John and his fellow farmers have been working nonstop to control the spread of the terrible bovine disease COWVID-19 across their farms.
Together, they oversee a collection of farms, conveniently numbered . The farms are connected by a set of roads such that any farm can be reached from farm by some sequence of roads.
Unfortunately, a cow in farm has just tested positive for COWVID-19. None of the other cows at that farm or at any other farms have the disease yet. However, knowing the contagious nature of the disease, Farmer John anticipates exactly one of the following adverse events on each successive day:
In a single farm, a "superspreader" event causes the number of cows at that farm with COWVID-19 to double;
A single cow with COWVID-19 moves along a road from one farm to an adjacent farm.
Farmer John is worried about how fast the outbreak might spread. Please help him by determining the minimum possible number of days before it could be the case that at least one cow in every farm has the disease.
Input
The first line contains the single integer . The next lines each contain two space-separated integers and describing a road between farms and . Both and are in the range .
Output
The minimum number of days until the outbreak could reach every farm.
Examples
One possible sequence of events corresponding to this example is the following: the number of sick cows in farm doubles and then doubles again, so that after two days, there are sick cows in farm . In each of the next days, a sick cow travels from farm to each of farms and respectively. After days, at least sick cow exists at each farm.