Problem B
Conquest
Nomads, Kingdoms, and Tribes are on the islands of the great seas. Bridges span between islands allowing travel between them. It is possible to get from every island to every other island through some sequence of bridges. The islands were at peace until everything changed when the Spanning Nation attacked!
Initially the Spanning Nation occupies island 1. From that point forward, the Spanning Nation can attack any island that is directly connected to some island already conquered by the Spanning Nation. Thankfully wars are resolved without any fighting. The Spanning Nation only attacks an island if the island’s army is strictly smaller than the Spanning Nation’s army. The smaller island army will simply concede and join the Spanning Nation’s army.
As the tactical advisor of the Spanning Nation, determine the maximum possible army size the Spanning Nation can have after making a series of attacks.
Input
The first line contains the integer
The next
The next
Output
Display the maximum possible army size of the Spanning Nation.
Sample Input 1 | Sample Output 1 |
---|---|
6 5 1 4 3 4 2 4 6 3 5 4 2 4 1 0 10 2 |
9 |
Sample Input 2 | Sample Output 2 |
---|---|
6 5 3 4 3 1 2 3 6 1 5 3 2 3 0 1 3 3 |
3 |