Description

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 a1, a2, ..., ak.

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 (ai ≠ b for every 1 ≤ i ≤ k) and choose a storage in some city s (s = aj 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.

Input

The first line of the input contains three integers nm 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 uv 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 a1, a2, ..., ak (1 ≤ ai ≤ n) — the number of cities having flour storage located in. If k = 0 then this line is not presented in the input.

Output

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.

Examples
input
5 4 2
1 2 5
1 2 3
2 3 4
1 4 10
1 5
output
3
input
3 1 1
1 2 3
3
output
-1
Note

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

正解:搜索

解题报告:

  直接搜索每个仓库有没有与非仓库直接相连,若相连则更新答案。显然可行。

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int MAXN = ;
const int MAXM = ;
const int inf = (<<);
int n,m,k,ecnt,ans;
int first[MAXN],next[MAXM],to[MAXM],w[MAXM];
bool in[MAXN]; inline int getint(){
int w=,q=;char c=getchar();
while(c!='-' && (c<'' || c>'')) c=getchar();
if(c=='-') q=-,c=getchar();
while(c>='' && c<='') w=w*+c-'',c=getchar();
return w*q;
} int main()
{
n=getint(); m=getint(); k=getint();
int x,y,z;
for(int i=;i<=m;i++){
x=getint(); y=getint(); z=getint();
next[++ecnt]=first[x]; first[x]=ecnt; to[ecnt]=y; w[ecnt]=z;
next[++ecnt]=first[y]; first[y]=ecnt; to[ecnt]=x; w[ecnt]=z;
}
for(int o=;o<=k;o++){
x=getint(); in[x]=;
}
ans=inf;
for(int i=;i<=n;i++) {
if(in[i]) for(int j=first[i];j;j=next[j]) if(!in[to[j]]) ans=min(ans,w[j]);
}
if(ans==inf) printf("-1"); else printf("%d",ans);
return ;
}

最新文章

  1. js 页面无滚动条添加滚轮事件
  2. 深入理解计算机系统(2.2)---布尔代数以及C语言上的位运算
  3. 【Alpha版本】 第五天 11.11
  4. July 7th, Week 28th Thursday, 2016
  5. Android错误:W/ResourceType(2411): No package identifier when getting value for resource number 0x
  6. nice和taskset命令
  7. 2437: [Noi2011]兔兔与蛋蛋 - BZOJ
  8. 玩转CSLA.NET小技巧系列二:使用WCF无法上传附件,提示413 Entity Too Large
  9. Android从相册中获取图片以及路径
  10. js Array数组的使用
  11. UPPH、UPH
  12. CCLayer在Touch事件(Standard Touch Delegate和Targeted Touch Delegate)
  13. 真机调试方法- IOS/Android移动设备
  14. pta总结3
  15. PTA_Have fun with numbers(C++)
  16. C#-Database-连接
  17. 阿里云申请ssl证书
  18. (转)db2top详解
  19. Cygwin命令
  20. python中从内部循环直接跳出多层循环

热门文章

  1. commit Commit changes to stable storage 对变化提交
  2. &lt;2013 12 01&gt; 一篇很好的关于windows编程的入门指导(2013年末写的,比较前沿)
  3. JFrame上添加、删除Jpanel后动态显示界面问题
  4. 在ie和chrome浏览器中滚动条样式的设置
  5. 使用QtConcurrent编写多线程程序(也可以阻塞)
  6. VCL控件组件大都应该重载TWinControl的虚函数WndProc来进行处理窗口消息的工作
  7. create ‘/.git/index.lock’: File exists.
  8. (转)fiddler使用简介--其三
  9. SQL语句 自连表查询。inner join用法,partition by ,列转行查询
  10. ArchiMate进行业务架构建模的参考