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][ ...
随机推荐
- 工作记录之开发HRM项目总结
开发HRM项目的步骤: 1:首先保留HRM项目中的两张表(Employee,Position)把这两张表中的数据内容复制到Operator-Portlet这个项目中,这两张表的service.xml配 ...
- Yahoo Programming Contest 2019
A - Anti-Adjacency 签. #include <bits/stdc++.h> using namespace std; int main() { int n, k; whi ...
- 2018 Multi-University Training Contest 6 Solution
A - oval-and-rectangle 题意:给出一个椭圆的a 和 b,在$[0, b]中随机选择c$ 使得四个顶点在椭圆上构成一个矩形,求矩形周长期望 思路:求出每种矩形的周长,除以b(积分) ...
- py文件生成pyc
鼠标右键 在此处打开命令行 python -m compileall xxx.py可以对当前目录下的xxx.py文件生成pyc
- ng-深度学习-课程笔记-5: 深层神经网络(Week4)
1 深度L层神经网络( Deep L-layer Neural network ) 针对具体问题很难判断需要几层的网络,所以先试试逻辑回归是比较合理的做法,然后再试试单隐层,把隐层数量当作一个超参数, ...
- bzoj1613 / P1353 [USACO08JAN]跑步Running
P1353 [USACO08JAN]跑步Running 显然的dp 设$f[i][j]$表示进行到第$i$分钟时,$j$疲劳度下的最远距离,$d[i]$为第$i$分钟下能跑的距离 分类讨论 1.运动: ...
- ubuntu下各类快捷键汇总记录
一.环境 Ubuntu 16.04 二.快捷键汇总如下 2.1 将图形界面下的terminal最大化:ctrl+super+向上的方向键 2.2 将图形界面下的terminal最小化:ctrl+sup ...
- 微信小程序路过——新手不要错过哦!
应该算是入门篇, 从我怎么0基础然后沿着什么方向走,遇到的什么坑,如何方向解决,不过本人接触不是很多,所以也就了解有限. 小程序的前提: 1.小程序大小不允许超过2M.(也就是本地图片,大图精图不要在 ...
- 双击不能运行可执行的jar文件
1.首先在命令行下运行jar包看文件是否报错(java -jar jar文件名称.jar) 如果程序中有System.out.println()语句,不想让其输出到控制台而保存到文件 ...
- python 递归求阶乘
#用递归函数求 n 阶乘的值 def factorial(i): : else: )# sum=n*(n-)!所以直接调用自身 n=int(input('请输入阶乘数:')) ): print('%d ...