#K65627. Minimum Maximum Road Capacity
Minimum Maximum Road Capacity
Minimum Maximum Road Capacity
You are given a set of n cities and m roads. Each city i has a given population a_i. A road connecting two cities u and v requires a capacity equal to \(\max(a_u,\,a_v)\). You are allowed to rearrange the roads (i.e. select a subset of roads) so that all cities become connected (forming a spanning tree), while minimizing the maximum road capacity used.
Your task is to compute the minimum possible value of the maximum road capacity that is required to ensure that any city can reach any other.
Note: The weight (or required capacity) of a road connecting cities u and v is defined as \(\max(a_u, a_v)\).
inputFormat
The input consists of multiple test cases. Each test case is formatted as follows:
- The first line contains two integers n and m, where n is the number of cities and m is the number of roads.
- The second line contains n integers representing the population of each city.
- The next m lines each contain two integers u and v representing a road between cities u and v.
A test case with a single line starting with "0" indicates the end of input.
outputFormat
For each test case, output a single integer on a new line, which is the minimum possible value of the maximum road capacity required to connect all the cities.
## sample4 4
100 200 300 400
1 2
2 3
3 4
4 1
5 5
10 20 30 40 50
1 2
2 3
3 4
4 5
5 1
3 3
500 600 700
1 2
2 3
3 1
0
400
50
700
</p>