#P15594. [ICPC 2020 Jakarta R] Exchange Bottleneck
[ICPC 2020 Jakarta R] Exchange Bottleneck
题目描述
The country of Bazbesonin currently has cities (numbered from to ) connected by bidirectional roads. When a pair of cities, and , would like to exchange a message, the latency is defined as the minimum number of roads required to go from to .
These cities have a long history in the past. Initially, city is constructed in the middle of Bazbesonin. Thereafter, the rest of the cities are constructed one after another from city to city . When constructing city , one or more bidirectional roads were also constructed depending on the economic condition of Bazbesonin at that time.
- If city was constructed when the economy was good, the roads connecting city and all cities constructed previously were constructed. In other words, the roads connecting city and city were constructed, for all .
- If city was constructed when the economy was bad, only the road connecting city and city was constructed.
The economic condition of Bazbesonin is represented by the binary array . If the economy was good when city was constructed, then the value of is . Otherwise, the value of is .
Back to the present day, each of the cities would like to exchange a message with every other city. The bottleneck of the exchange is the maximum latency among all pairs of cities. We would like to compute the bottleneck of the message exchange.
For example, let and . The cities and roads in Bazbesonin can be illustrated by the following figure:
:::align{center}
:::
- The latency of city and city is .
- The latency of city and city is .
- The latency of city and city is .
- The latency of city and city is .
- The latency of city and city is .
- The latency of city and city is .
- The latency of city and city is .
- The latency of city and city is .
- The latency of city and city is .
- The latency of city and city is .
Therefore, the bottleneck in this example is .
输入格式
Input begins with a line containing an integer: () representing the number of cities in Bazbesonin. The next line contains integers: () representing the economic condition of Bazbesonin.
输出格式
Output in a line an integer representing the bottleneck of the message exchange.
5
1 0 1 0
2
7
1 1 1 1 1 1
1
提示
Explanation for the sample input/output #1
This is the example from the problem description.
Explanation for the sample input/output #2
Each pair of cities is connected by a road, and thus their latencies are .