Bakery
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 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 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.
Example
5 4 2
1 2 5
1 2 3
2 3 4
1 4 10
1 5
3
3 1 1
1 2 3
3
-1
Note
Image illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened.
找出一条边距离最短且连接着一个flour storage,而自身并不是flour storage的地方作为bakery
代码:
#include <bits/stdc++.h> using namespace std; int main()
{
int u[],v[],w[];
int vis[] ={};
int n,m,k,d,s = 0x3fffffff;
cin>>n>>m>>k;
for(int i = ;i < m;i ++)
cin>>u[i]>>v[i]>>w[i];
for(int i = ;i < k;i ++)
{
cin>>d;
vis[d] = ;
}
for(int i = ;i < m;i ++)
{
if((vis[u[i]]^vis[v[i]]))
{
if(s > w[i])s = w[i];
}
}
if(s!=0x3fffffff)cout<<s;
else cout<<-;
}
Bakery的更多相关文章
- Codeforeces 707B Bakery(BFS)
B. Bakery time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...
- Codeforces Round #368 (Div. 2) B. Bakery (模拟)
Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...
- 信号量和PV操作写出Bakery算法的同步程序
面包店烹制面包及蛋糕,由n个销售员卖出.当有顾客进店购买面包或蛋糕时,应先在取号机上取号,然后等待叫号,若有销售员空闲时便叫下一号,试用信号量和PV操作写出Bakery算法的同步程序. 设计要求 1) ...
- Codeforces 834D The Bakery【dp+线段树维护+lazy】
D. The Bakery time limit per test:2.5 seconds memory limit per test:256 megabytes input:standard inp ...
- Codeforces 834D The Bakery - 动态规划 - 线段树
Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredient ...
- Codeforces Round #426 (Div. 1) B The Bakery (线段树+dp)
B. The Bakery time limit per test 2.5 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #368 (Div. 2) B. Bakery 水题
B. Bakery 题目连接: http://www.codeforces.com/contest/707/problem/B Description Masha wants to open her ...
- Codeforces 834D - The Bakery(dp+线段树)
834D - The Bakery 思路:dp[i][j]表示到第j个数为止分成i段的最大总和值. dp[i][j]=max{dp[i-1][x]+c(x+1,j)(i-1≤x≤j-1)},c(x+1 ...
- CF833B The Bakery 线段树,DP
CF833B The Bakery LG传送门 线段树优化DP. 其实这是很久以前就应该做了的一道题,由于颓废一直咕在那里,其实还是挺不错的一道题. 先考虑\(O(n^2k)\)做法:设\(f[i][ ...
随机推荐
- 2.2 The Object Model -- Reopening Classes and Instances
1. 你不需要一开始定义一个类的全部内容,你可以通过使用reopen方法重新打开一个类并定义新的属性. Person.reopen({ isPerson: true }); Person.create ...
- 11月16host文件
#################################################################################################### ...
- Linux笔记 #05# 断开远程连接后保持程序运行
教程:Linux 技巧:让进程在后台可靠运行的几种方法 网上搜索了一下,方法很多,选用最流行的 screen 命令参考:http://man.linuxde.net/screen 1. 安装 root ...
- ubuntu/centos/mac/windows 使用阿里源加速docker镜像下载
官方下载docker比较慢,阿里提供云容器hub, 1.打开阿里容器hub https://dev.aliyun.com/search.html 该页面右上方有一个管理中心,点击进去 2.选择镜像加速 ...
- c++生成算式并计算(《构建之法》第一章课后第一题)
c++实现计算器(自动生成算式并计算) 要满足的需求有以下几个: 自动生成随机的四则运算算式,包含括号和小数. 对生成的算式计算出结果. 算式.结果分别存储到不同的文件. 一 生成算式 由上述需求可知 ...
- ESXi主机遗忘密码重置密码
ESXi版本:6.0.0 VMware-VMvisor-Installer-6.0.0.update02-3620759.x86_64-Dell_Customized-A00.iso 使用和服务器系统 ...
- 【spring-boot】 springboot整合quartz实现定时任务
在做项目时有时候会有定时器任务的功能,比如某某时间应该做什么,多少秒应该怎么样之类的. spring支持多种定时任务的实现.我们来介绍下使用spring的定时器和使用quartz定时器 1.我们使用s ...
- python 获取列表的键值对
nums = [, , , , ] for num_index, num_val in enumerate(nums): print(num_index, num_val)
- ffmpeg_资料_01
1. 用ffmpeg制作推流工具,实现推流系统声音和桌面到rtmp服务器-CSDN论坛-CSDN.NET-中国最大的IT技术社区.html http://bbs.csdn.net/topics/392 ...
- SSH基本管理和配置文件的使用
服务端:linl_S IP:10.0.0.15 客户端:lin_C IP:10.0.0.16 SSHD服务 SSH协议:安全外壳协议.为Secure Shell的缩写.SSH为建立在应 ...