### 题解

#include<bits/stdc++.h>
#define Re register
#define fo(i, a, b) for (Re int i = (a); i <= (b); ++i)
#define fd(i, a, b) for (Re int i = (a); i >= (b); --i)
#define edge(i, u) for (Re int i = head[u], v = e[i].v; i; i = e[i].nxt, v = e[i].v)
#define pb push_back
#define F first
#define S second
#define ll long long
#define inf 1000000007
#define mp std::make_pair
#define mod 1000000007
#define eps 1e-4
#define lowbit(x) (x & -x)
#define N 100005
#define ls tr[u].s[0]
#define rs tr[u].s[1]
#define cl(arr) memset(arr, 0, sizeof arr)
#define pi std::pair<ll, int>
int head[N], tot, f[N][2], k, a[N], n, m, T, cnt;
ll dis[N][2], ans;
bool fl[N];
struct edge {
int nxt, v, w;
} e[N << 3];
inline void addedge (int u, int v, int w)
{
e[++tot] = (edge) {head[u], v, w};
}
std::map<pi, int> uni;
inline void clear ()
{
cl(fl);
cl(f);
uni.clear();
tot = 0; cnt = 0;
}
std::priority_queue< pi > q;
inline int check (int v, int dist)
{
return dis[v][0] > dist ? 0 : dis[v][1] > dist ? 1 : -1;
}
inline void bfs ()
{
memset(dis, 0x3f, sizeof dis);
ans = dis[0][0];
fo (i, 1, k) { fl[a[i]] = 1; dis[a[i]][0] = dis[a[i]][1] = 0; q.push(mp(0, a[i])); f[a[i]][0] = f[a[i]][1] = a[i]; }
while (!q.empty())
{
pi tmp = q.top(); q.pop();
int u = tmp.S, dist = -tmp.F, now, last;
if (dis[u][1] < dist) continue;
last = (dis[u][0] == dist) ? 0 : 1;
if (f[u][last] == 0) continue;
edge (i, u)
{
if (dis[v][0] > dist + e[i].w)
{
if (f[v][0] != f[u][last])
{
dis[v][1] = dis[v][0]; f[v][1] = f[v][0];
dis[v][0] = dist + e[i].w;
f[v][0] = f[u][last];
}
else
{
dis[v][0] = dist + e[i].w;
}
q.push(mp(-dis[v][0], v));
}
else
{
if (dis[v][1] > dist + e[i].w && f[v][0] != f[u][last])
{
dis[v][1] = dist + e[i].w;
f[v][1] = f[u][last];
q.push(mp(-dis[v][1], v));
}
}
}
}
}
ll uu[N << 3], vv[N << 3], ww[N << 3];
main ()
{
scanf("%d", &T);
while (T--)
{
clear();
scanf("%d %d %d", &n, &m, &k);
fo (i, 1, m)
{
int u, v, w;
scanf("%d %d %d", &u, &v, &w);
if (u == v) continue;
if (uni.find(mp(u, v)) != uni.end() && uni[mp(u, v)] < w) continue;
uni[mp(u, v)] = w;
}
for (std::map<pi, int>::iterator it = uni.begin(); it != uni.end(); ++it)
{
uu[++cnt] = it -> F.F; vv[cnt] = it -> F.S; ww[cnt] = it -> S;
}
fo (i, 1, k) scanf("%d", &a[i]);
bfs();
fo (i, 1, cnt)
if (fl[vv[i]])
{
if (f[uu[i]][0] != vv[i])
ans = std::min(ans, ww[i] + dis[uu[i]][0]);
else
ans = std::min(ans, ww[i] + dis[uu[i]][1]);
}
printf("%lld\n", ans);
}
}