#P15604. [ICPC 2021 Jakarta R] Bicycle Tour
[ICPC 2021 Jakarta R] Bicycle Tour
题目描述
There are junctions in Jakarta (numbered from to ) that are connected by bidirectional roads such that from any junction you can reach any other junctions by going through one or more roads. The junction has a height of .
Ahmad loves to cycle, especially on flat roads. He argues that you need more power to cycle if the road is uphill or downhill. Specifically, to cycle on a road connecting junction and junction , you will require a power of . The required power to cycle a set of roads is equal to the highest required power to cycle each of those roads. For example, let there be roads where each requires a power of , , and to cycle, then the required power to cycle through all those roads is .
A cycling route from junction is defined as a tour that starts at junction , going to one or more other junctions while not using the same road more than once, and ends at the same junction .
Ahmad would like to find a cycling route from each junction that has a minimum required power, and that is your task in this problem. For each junction, you need to output the required power of a cycling route from that junction that has the minimum required power. There might be a case where a cycling route from a junction is not possible; in such a case, the output should be for the respective junction.
For example, let , , , and the roads be shown in the following figure. The label on each node indicates the junction number while the number on each edge indicates the required power to cycle through that road. Notice that the required power to cycle through each road can be obtained from the given .
:::align{center}
:::
The following are the cycling routes with the minimum required power from each junction:
- Junction : $1 \rightarrow 2 \rightarrow 7 \rightarrow 6 \rightarrow 1$, with a required power of .
- Junction : $2 \rightarrow 1 \rightarrow 6 \rightarrow 7 \rightarrow 2$, with a required power of .
- Junction : , with a required power of .
- There is no possible cycling route from junction .
- Junction : $5 \rightarrow 3 \rightarrow 1 \rightarrow 2 \rightarrow 5$, with a required power of .
- Junction : , with a required power of .
- Junction : , with a required power of .
- Junction : , with a required power of .
输入格式
Input begins with a line containing two integers (; ) representing the number of junctions and the number of bidirectional roads, respectively. The second line contains integers () representing the height of the junction. The next lines, each contains two integers () representing a bidirectional road connecting junction and . It is guaranteed that from any junction you can reach any other junctions by going through one or more roads. It is also guaranteed that for any pairs of junctions , there is at most one bidirectional road connecting junction and junction .
输出格式
Output contains integers in a line each separated by a single space. The integer represents the required power of a cycling route from junction with the minimum required power. If there is no possible cycling route from junction , then the integer is .
8 11
5 2 7 0 10 6 6 6
1 2
1 3
2 3
2 4
2 5
2 7
3 5
1 6
6 7
6 8
7 8
4 4 5 -1 8 0 0 0
4 5
10 20 30 40
1 2
1 3
1 4
2 3
3 4
20 20 20 30
5 4
72 35 22 49 108
1 2
2 3
3 4
4 5
-1 -1 -1 -1 -1