CF1081D.Maximum Distance

传统题 时间 1000 ms 内存 256 MiB 8 尝试 20 已通过 7 标签

Maximum Distance

CF1081D · Maximum Distance

英文原题面

Statement

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 nn vertices and mm weighted edges. There are kk special vertices: x1,x2,,xkx_1, x_2, \ldots, x_k. 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.

Input

The first line contains three integers nn, mm and kk (2kn1052 \leq k \leq n \leq 10^5, n1m105n-1 \leq m \leq 10^5) — the number of vertices, the number of edges and the number of special vertices. The second line contains kk distinct integers x1,x2,,xkx_1, x_2, \ldots, x_k (1xin1 \leq x_i \leq n). Each of the following mm lines contains three integers uu, vv and ww (1u,vn,1w1091 \leq u,v \leq n, 1 \leq w \leq 10^9), denoting there is an edge between uu and vv of weight ww. The given graph is undirected, so an edge (u,v)(u, v) 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 kk integers. The ii-th integer is the distance between xix_i and the farthest special vertex from it.

样例

样例 1

输入:

2 3 2
2 1
1 2 3
1 2 2
2 2 1

输出:

2 2 

样例 2

输入:

4 5 3
1 2 3
1 2 5
4 2 1
2 3 2
1 4 4
1 3 3

输出:

3 3 3 

样例解释(英文原文)

In the first example, the distance between vertex 11 and 22 equals to 22 because one can walk through the edge of weight 22 connecting them. So the distance to the farthest node for both 11 and 22 equals to 22. In the second example, one can find that distance between 11 and 22, distance between 11 and 33 are both 33 and the distance between 22 and 33 is 22. The graph may have multiple edges between and self-loops, as in the first example.

在线编程 IDE

建议全屏模式获得最佳体验