/*
题目很简单就是求最短路,其实跟hdu 2066差不多的
加入一个0点,把kiki能到的s点与0点相连,map[0][p] = 0;
接下来就是很简单的求最短路,注意这个是有向图
*/
#include <iostream>//2566318 2010-07-02 15:15:37 Accepted 2680 234MS 4252K 1410 B C++ 悔惜晟
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
const int M = 1005;
const int MAX = 0x3fffffff;
int dis[M];
int map[M][M];
int n, s;
bool hash[M];
struct node
{
int num;
int dis;
friend bool operator < (node a, node b)
{
return a.dis > b.dis;
}
};
void BFS()
{
priority_queue<node> Q;
node N, P;
for(int i = 1; i <= n; i++)
{
if(map[0][i] != MAX)
{
N.num = i;
N.dis = 0;
Q.push(N);
}
}
memset(hash, false, sizeof(hash));
hash[0] = true;
dis[0] = 0;
while(!Q.empty())
{
P = Q.top();
Q.pop();
hash[P.num] = true;
for(int j = 1; j <= n; j++)
{
if(!hash[j] && map[P.num][j] + P.dis < dis[j])
{
dis[j] = map[P.num][j] + P.dis;
N.dis = dis[j];
N.num = j;
Q.push(N);
}
}
}
if(dis[s] == MAX)
printf("-1/n");
else
printf("%d/n", dis[s]);
}
int main()
{
int m, w;
while(scanf("%d %d %d", &n, &m, &s) != EOF)
{
int a, b, t;
for(int i = 0; i < M; i++)
for(int j = 0; j < M; j++)
{
map[i][j] = MAX;
}
while(m--)
{
scanf("%d %d %d", &a, &b, &t);
if(t < map[a][b])
{
map[a][b] = t ;//map[b][a] = t;
}//means from station p to station q there is a way and it will costs t minutes .
} //一开始就错在这句话上。
scanf("%d", &w);
while(w--)
{
scanf("%d", &a);
map[0][a] = map[a][0] = 0;
}
for(int i = 0; i <= n; i++)
dis[i] = map[0][i];
BFS();
}
}