CF707B.Bakery

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.

To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities numbered _a_1, _a_2, ..., a__k.

Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another n - k cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble.

Formally, Masha will pay x roubles, if she will open the bakery in some city b (a__i ≠ b for every 1 ≤ i ≤ k) and choose a storage in some city s (s = a__j for some 1 ≤ j ≤ k) and b and s are connected by some path of roads of summary length x (if there are more than one path, Masha is able to choose which of them should be used).

Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of k storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount.

玛莎想开一家自己的面包店,并在编号为 11 到 nn 的 nn 个城市中的某一个城市里烤松饼。城市之间共有 mm 条双向道路,每条道路连接某两个城市。

为了在面包店中烤制松饼,玛莎需要从某个面粉仓库获取原料供应。全国仅有 kk 个面粉仓库,分别位于不同的城市,其编号为 a1, a2, …, aka_1,\,a_2,\,\dots,\,a_k。

不幸的是,玛莎所居住国家的法律禁止在任何设有面粉仓库的城市中开设面包店。因此,她只能在其余 n−kn - k 个城市中选择一个来开设面包店。当然,面粉运输是需要付费的——仓库与面包店之间每公里道路长度需支付 1 卢布。

形式化地说:若玛莎将面包店开设在城市 bb(满足对所有 1≤i≤k1 \le i \le k,均有 ai≠ba_i \ne b),并选择位于城市 ss(其中 s=ajs = a_j,对某个 1≤j≤k1 \le j \le k)的仓库,且 bb 与 ss 之间存在一条总长度为 xx 的道路路径(若存在多条路径,玛莎可任选其一),则她需支付 xx 卢布。

玛莎非常节俭且理性。她希望找到一个可开设面包店的城市(并从中选择 kk 个仓库之一,以及该城市与仓库所在城市之间的一条路径),使得面粉运输费用最小。请帮助玛莎找出这一最小费用。

输入格式

The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 105, 0 ≤ k ≤ n) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively.

Then m lines follow. Each of them contains three integers u, v and l (1 ≤ u, v ≤ n, 1 ≤ l ≤ 109, u ≠ v) meaning that there is a road between cities u and v of length of l kilometers .

If k > 0, then the last line of the input contains k distinct integers _a_1, _a_2, ..., a__k (1 ≤ a__i ≤ n) — the number of cities having flour storage located in. If k = 0 then this line is not presented in the input.

输入的第一行包含三个整数 nn、mm 和 kk(1≤n,m≤1051 \leq n, m \leq 10^5,0≤k≤n0 \leq k \leq n),分别表示玛莎所居住的国家中的城市数量、城市之间的道路数量以及面粉仓库的数量。

接下来是 mm 行。每行包含三个整数 uu、vv 和 ll(1≤u,v≤n1 \leq u, v \leq n,1≤l≤1091 \leq l \leq 10^9,u≠vu \neq v),表示在城市 uu 与城市 vv 之间存在一条长度为 ll 千米的道路。

若 k>0k > 0,则输入的最后一行包含 kk 个互不相同的整数 a1,a2,…,aka_1, a_2, \dots, a_k(1≤ai≤n1 \leq a_i \leq n),表示设有面粉仓库的城市编号;若 k=0k = 0,则该行不会出现在输入中。

输出格式

Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line.

If the bakery can not be opened (while satisfying conditions) in any of the n cities, print  - 1 in the only line.

输出玛莎为面粉配送所需支付的最少卢布数,仅在一行中输出。

如果无法在任意一个 n 个城市中(且满足所有条件)开设面包店,则仅在一行中输出  - 1。

输入输出样例

  • 输入#1

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

    输出#1

    3
  • 输入#2

    3 1 1
    1 2 3
    3

    输出#2

    -1

说明/提示

Image illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened.

图中展示了第一个样例。图中加粗(加深)显示了设有仓库的城市以及构成答案的道路。

输入解题思路,AI测评打分。不知道怎么写?

首页