B. Bakery time limit/test 2 seconds memory limit per test 256 megabytes input standard input output standard output
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 the supply from some. There are only K storages and located in different cities numbered, A1, ..., AK.
Unforunately the country Masha lives in prohibits opening bakery in any of the cities which has storage In it. She can open it only in one of another n-k cities, and, of course, flour delivery, should to be paid-for every kilometer o F Path between storage and bakery Masha should pay 1 ruble.
Formally, Masha'll pay x roubles, if she is open the bakery in some City B (ai≠b for every 1≤i≤k) and choose a s Torage in some city s (s = AJ for some 1≤j≤k) and B and s are connected by some path of roads of summary of length x (if There are more than one path, Masha are able to choose which of them to should).
Masha is very thrifty and rational. She 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. Please help Masha find this amount. Input
The "I" of the input contains three integers n, m and K (1≤n, m≤105, 0≤k≤n)-the number of cities in count Ry Masha lives in, the number of roads between them and the number of flour storages.
Then m lines follow. Each of the them contains three integers u, V and L (1≤u, V≤n, 1≤l≤109, u≠v) meaning that there is a road between CI Ties 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 CIT IES has flour storage located in. If k = 0 Then this is not presented in the input. Output
Print the minimum possible amount of rubles Masha should pay for flour to the only line.
If The bakery can is opened (while satisfying conditions) in any of the N cities, and Print-1 in the only line. Examples input
5 4 2 1 2 5 1 2 3 2 3 4 1 4
ten
1 5
Output
3
Input
3 1 1
1 2 3
3
Output
-1
Note
Image illustrates the "the" Cities with storage located in and the road representing the answer are.
To give you a map, there are K special points, others are ordinary points, let you find a shortest edge, connect special points and ordinary points.
The puzzle: All the edges are taken out to compare it.
Code:
#pragma COMMENT (linker, "/stack:102400000,102400000")//#include <bits/stdc++.h> #include <stdio.h> # include<string.h> #include <algorithm> #include <iostream> #include <cstring> #include < vector> #include <map> #include <cmath> #include <queue> #include <set> #include <stack
> #include <utility> using namespace std;
typedef long Long LL;
typedef unsigned long long ull; #define MST (a) memset (a, 0, sizeof (a)) #define M_P (x,y) Make_pair (x,y) #define REP (i,j,k) for (int i = j; I <= K; i++ #define/i,j,k for (int i = j; I >= K; i--) #define Lson x << 1, L, mid #define Rson x << 1 |
1, Mid + 1, r const int lowbit (int x) {return x&-x;}
Const double EPS = 1e-8;
const int INF = 1E9+7;
CONST LL inf = (1ll<<62);
const int MOD = 1e9 + 7;
CONST LL mod = (1ll<<32);
const int N = 101010;
const int m=100010; Template <class T1, class t2>inline void Getmax (T1 &a, T2 b{if (b>a) a = b;}
Template <class T1, class t2>inline void Getmin (T1 &a, T2 b) {if (b<a) a = b;} int read () {int v = 0, f = 1;
Char c =getchar ();
while (C < | | < c) {if (c== '-') f =-1;
c = GetChar ();
while (<= c && c <=) v = v*10+c-48, c = GetChar ();
return v*f;
int N,m,k,f[n],x[n],y[n],l[n],t,ans=int_max;
int main () {#ifndef Online_judge freopen ("In.txt", "R", stdin);
#endif scanf ("%d%d%d", &n,&m,&k);
for (int i=1;i<=m;i++) scanf ("%d%d%d", x+i,y+i,l+i);
for (int i=1;i<=k;i++) scanf ("%d", &t), f[t]=1;
for (int i=1;i<=m;i++) {if (F[x[i]]^f[y[i]]) ans=min (ans,l[i));
} if (Ans==int_max) puts ("-1");
else printf ("%d\n", ans);
return 0;
}