#P1081D. Maximum Distance
Maximum Distance
Description
Chouti was tired of the tedious homework, so he opened up an old programming problem he created years ago.
You are given a connected undirected graph with vertices and weighted edges. There are special vertices: .
Let's define the cost of the path as the maximum weight of the edges in it. And the distance between two vertexes as the minimum cost of the paths connecting them.
For each special vertex, find another special vertex which is farthest from it (in terms of the previous paragraph, i.e. the corresponding distance is maximum possible) and output the distance between them.
The original constraints are really small so he thought the problem was boring. Now, he raises the constraints and hopes you can solve it for him.
The first line contains three integers , and (, ) — the number of vertices, the number of edges and the number of special vertices.
The second line contains distinct integers ().
Each of the following lines contains three integers , and (), denoting there is an edge between and of weight . The given graph is undirected, so an edge can be used in the both directions.
The graph may have multiple edges and self-loops.
It is guaranteed, that the graph is connected.
The first and only line should contain integers. The -th integer is the distance between and the farthest special vertex from it.
Input
The first line contains three integers , and (, ) — the number of vertices, the number of edges and the number of special vertices.
The second line contains distinct integers ().
Each of the following lines contains three integers , and (), denoting there is an edge between and of weight . The given graph is undirected, so an edge can be used in the both directions.
The graph may have multiple edges and self-loops.
It is guaranteed, that the graph is connected.
Output
The first and only line should contain integers. The -th integer is the distance between and the farthest special vertex from it.
Note
In the first example, the distance between vertex and equals to because one can walk through the edge of weight connecting them. So the distance to the farthest node for both and equals to .
In the second example, one can find that distance between and , distance between and are both and the distance between and is .
The graph may have multiple edges between and self-loops, as in the first example.