#P15594. [ICPC 2020 Jakarta R] Exchange Bottleneck

[ICPC 2020 Jakarta R] Exchange Bottleneck

题目描述

The country of Bazbesonin currently has NN cities (numbered from 11 to NN) connected by bidirectional roads. When a pair of cities, uu and vv, would like to exchange a message, the latency is defined as the minimum number of roads required to go from uu to vv.

These cities have a long history in the past. Initially, city 11 is constructed in the middle of Bazbesonin. Thereafter, the rest of the cities are constructed one after another from city 22 to city NN. When constructing city xx, one or more bidirectional roads were also constructed depending on the economic condition of Bazbesonin at that time.

  • If city xx was constructed when the economy was good, the roads connecting city xx and all cities constructed previously were constructed. In other words, the roads connecting city xx and city yy were constructed, for all 1y<x1 \leq y < x.
  • If city xx was constructed when the economy was bad, only the road connecting city xx and city x1x-1 was constructed.

The economic condition of Bazbesonin is represented by the binary array E1...N1E_{1...N-1}. If the economy was good when city xx was constructed, then the value of Ex1E_{x-1} is 11. Otherwise, the value of Ex1E_{x-1} is 00.

Back to the present day, each of the NN 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 N=5N = 5 and B1...4=[1,0,1,0]B_{1...4} = [1, 0, 1, 0]. The cities and roads in Bazbesonin can be illustrated by the following figure:

:::align{center} :::

  • The latency of city 11 and city 22 is 11.
  • The latency of city 11 and city 33 is 22.
  • The latency of city 11 and city 44 is 11.
  • The latency of city 11 and city 55 is 22.
  • The latency of city 22 and city 33 is 11.
  • The latency of city 22 and city 44 is 11.
  • The latency of city 22 and city 55 is 22.
  • The latency of city 33 and city 44 is 11.
  • The latency of city 33 and city 55 is 22.
  • The latency of city 44 and city 55 is 11.

Therefore, the bottleneck in this example is 22.

输入格式

Input begins with a line containing an integer: NN (2N1000002 \leq N \leq 100\,000) representing the number of cities in Bazbesonin. The next line contains N1N-1 integers: EiE_i (Ei{0,1}E_i \in \{0,1\}) 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 11.