HDU 2066
#include
#include
#include
#include
#include
#include
#include
#include
#define MAXN 1005
#define MAXM 305
#define MOD 10000
#define inf 100000000
#define eps 1e-9
#define pi acos(-1.0)
typedef long long LL;
using namespace std;
int T, S, D, a, b, t, u, v, w, x, n;
int mat[MAXN][MAXN], dis[MAXN], lin[MAXN], ed[MAXN];
bool vis[MAXN];
void Dijkstra() {
memset(vis, false, sizeof(vis));
memset(dis, 0x3f, sizeof(dis)); dis[0] = 0;
for (int i = 0; i < n; i++) {
int k = -1;
for (int j = 0; j <= n; j++) {
if (!vis[j] && (k == -1 || dis[j] < dis[k]))
k = j;
}
vis[k] = true;
for (int j = 0; j <= n; j++) {
if (!vis[j] && mat[k][j] != -1 && dis[k] + mat[k][j] < dis[j])
dis[j] = dis[k] + mat[k][j];
}
}
}
int main() {
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
while (scanf("%d %d %d", &T, &S, &D) != EOF) {
memset(mat, -1, sizeof(mat));
n = 0;
for (int i = 0; i < T; i++) {
scanf("%d %d %d", &u, &v, &w);
if (mat[u][v] == -1 || mat[u][v] > w)
mat[u][v] = mat[v][u] = w;
n = max(n, max(u, v));
}
for (int i = 0; i < S; i++) {
scanf("%d", &x);
mat[0][x] = mat[x][0] = 0;
}
for (int i = 0; i < D; i++)
scanf("%d", &ed[i]);
Dijkstra();
int ans = dis[ed[0]];
for (int i = 1; i < D; i++) ans = min(ans, dis[ed[i]]);
printf("%d\n", ans);
}
return 0;
}