#include<bits/stdc++.h> //NeOWami
using namespace std;
#define ft first
#define sc second
#define int long long
using pii = pair<int, int>;
template <class T> using heapmin = priority_queue<T, vector<T>, greater<T>>;
const int N = 2e5 + 5;
const int inf = 1e17;
int n, m, k;
int DB[N];
bool isDB[N];
vector<pii> G[N];
namespace sub1 {
int dist[N], ans[N];
void dijkstra(int root) {
for (int i = 1; i <= n; i++) dist[i] = inf;
dist[root] = 0;
heapmin<pii> Q;
Q.push({0, root});
while(!Q.empty()) {
int u = Q.top().sc, old = Q.top().ft;
Q.pop();
if (old != dist[u]) continue;
if (isDB[u] && u != root) ans[u] = min(ans[u], old);
for (pii item: G[u]) {
int v = item.ft, w = item.sc + old;
if (w < dist[v]) {
dist[v] = w;
Q.push({w, v});
}
}
}
}
void solve() {
for (int i = 1; i <= n; i++) ans[i] = inf;
for (int i = 1; i <= k; i++) {
dijkstra(DB[i]);
}
for (int i = 1; i <= k; i++) {
int u = DB[i];
if (ans[u] == inf) cout << "-1\n";
else cout << ans[u] << "\n";
}
}
};
namespace subfull {
int dist[N], root[N], ans[N];
using pipii = pair<int, pii>;
void solve() {
for (int i = 1; i <= n; i++) ans[i] = inf, dist[i] = inf;
heapmin<pipii> Q;
for (int i = 1; i <= k; i++) {
int u = DB[i];
root[u] = u;
dist[u] = 0;
Q.push({0, {u, u}});
}
while(!Q.empty()) {
int old = Q.top().ft, u = Q.top().sc.ft, rt = Q.top().sc.sc;
Q.pop();
if (old != dist[u]) {
if (rt != root[u]) {
ans[rt] = min(ans[rt], dist[u] + old);
ans[root[u]] = min(ans[root[u]], dist[u] + old);
}
continue;
}
for (pii item: G[u]) {
int v = item.ft, w = item.sc + old;
if (rt != root[v]) {
ans[rt] = min(ans[rt], dist[v] + w);
ans[root[v]] = min(ans[root[v]], dist[v] + w);
}
if (w < dist[v]) {
dist[v] = w;
root[v] = rt;
Q.push({w, {v, rt}});
}
}
}
for (int i = 1; i <= k; i++) {
int u = DB[i];
if (ans[u] == inf) cout << "-1\n";
else cout << ans[u] << "\n";
}
}
};
signed main() {
cin.tie(NULL)->sync_with_stdio(false); cout.tie(NULL);
if (ifstream("DB.INP")) {
freopen("DB.INP", "r", stdin);
freopen("DB.OUT", "w", stdout);
}
cin >> n >> m >> k;
for (int i = 1; i <= m; i++) {
int u, v, w; cin >> u >> v >> w;
G[u].push_back({v, w});
G[v].push_back({u, w});
}
for (int i = 1; i <= k; i++){
cin >> DB[i];
isDB[DB[i]] = 1 ;
}
// if (n <= 200) return sub1::solve(), 0;
return subfull::solve(), 0;
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4gLy9OZU9XYW1pCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgojZGVmaW5lIGZ0IGZpcnN0CiNkZWZpbmUgc2Mgc2Vjb25kCiNkZWZpbmUgaW50IGxvbmcgbG9uZwp1c2luZyBwaWkgPSBwYWlyPGludCwgaW50PjsKdGVtcGxhdGUgPGNsYXNzIFQ+IHVzaW5nIGhlYXBtaW4gPSBwcmlvcml0eV9xdWV1ZTxULCB2ZWN0b3I8VD4sIGdyZWF0ZXI8VD4+Owpjb25zdCBpbnQgTiA9IDJlNSArIDU7CmNvbnN0IGludCBpbmYgPSAxZTE3OwppbnQgbiwgbSwgazsKaW50IERCW05dOwpib29sIGlzREJbTl07CnZlY3RvcjxwaWk+IEdbTl07Cm5hbWVzcGFjZSBzdWIxIHsKaW50IGRpc3RbTl0sIGFuc1tOXTsKdm9pZCBkaWprc3RyYShpbnQgcm9vdCkgewogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKSBkaXN0W2ldID0gaW5mOwoKICAgIGRpc3Rbcm9vdF0gPSAwOwogICAgaGVhcG1pbjxwaWk+IFE7CiAgICAgUS5wdXNoKHswLCByb290fSk7CiAgICAgd2hpbGUoIVEuZW1wdHkoKSkgewogICAgICAgIGludCB1ID0gUS50b3AoKS5zYywgb2xkID0gUS50b3AoKS5mdDsKICAgICAgICBRLnBvcCgpOwogICAgICAgIGlmIChvbGQgIT0gZGlzdFt1XSkgY29udGludWU7CiAgICAgICAgaWYgKGlzREJbdV0gJiYgdSAhPSByb290KSBhbnNbdV0gPSBtaW4oYW5zW3VdLCBvbGQpOwogICAgICAgIGZvciAocGlpIGl0ZW06IEdbdV0pIHsKICAgICAgICAgICAgaW50IHYgPSBpdGVtLmZ0LCB3ID0gaXRlbS5zYyArIG9sZDsKICAgICAgICAgICAgaWYgKHcgPCBkaXN0W3ZdKSB7CiAgICAgICAgICAgICAgICBkaXN0W3ZdID0gdzsKICAgICAgICAgICAgICAgIFEucHVzaCh7dywgdn0pOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgIH0KfQp2b2lkIHNvbHZlKCkgewogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgaSsrKSBhbnNbaV0gPSBpbmY7CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBrOyBpKyspIHsKICAgICAgICBkaWprc3RyYShEQltpXSk7CiAgICB9CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBrOyBpKyspIHsKICAgICAgICBpbnQgdSA9IERCW2ldOwogICAgICAgIGlmIChhbnNbdV0gPT0gaW5mKSBjb3V0IDw8ICItMVxuIjsKICAgICAgICBlbHNlIGNvdXQgPDwgYW5zW3VdIDw8ICJcbiI7CiAgICB9Cn0KfTsKCm5hbWVzcGFjZSBzdWJmdWxsIHsKaW50IGRpc3RbTl0sIHJvb3RbTl0sIGFuc1tOXTsKdXNpbmcgcGlwaWkgPSBwYWlyPGludCwgcGlpPjsKdm9pZCBzb2x2ZSgpIHsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47IGkrKykgYW5zW2ldID0gaW5mLCBkaXN0W2ldID0gaW5mOwogICAgaGVhcG1pbjxwaXBpaT4gUTsKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IGs7IGkrKykgewogICAgICAgIGludCB1ID0gREJbaV07CiAgICAgICAgcm9vdFt1XSA9IHU7CiAgICAgICAgZGlzdFt1XSA9IDA7CiAgICAgICAgUS5wdXNoKHswLCB7dSwgdX19KTsKICAgIH0KICAgIHdoaWxlKCFRLmVtcHR5KCkpIHsKICAgICAgICBpbnQgb2xkID0gUS50b3AoKS5mdCwgdSA9IFEudG9wKCkuc2MuZnQsIHJ0ID0gUS50b3AoKS5zYy5zYzsKICAgICAgICBRLnBvcCgpOwogICAgICAgIGlmIChvbGQgIT0gZGlzdFt1XSkgewogICAgICAgICAgICBpZiAocnQgIT0gcm9vdFt1XSkgewogICAgICAgICAgICAgICAgYW5zW3J0XSA9IG1pbihhbnNbcnRdLCBkaXN0W3VdICsgb2xkKTsKICAgICAgICAgICAgICAgIGFuc1tyb290W3VdXSA9IG1pbihhbnNbcm9vdFt1XV0sIGRpc3RbdV0gKyBvbGQpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0KICAgICAgICBmb3IgKHBpaSBpdGVtOiBHW3VdKSB7CiAgICAgICAgICAgIGludCB2ID0gaXRlbS5mdCwgdyA9IGl0ZW0uc2MgKyBvbGQ7CiAgICAgICAgICAgIGlmIChydCAhPSByb290W3ZdKSB7CiAgICAgICAgICAgICAgICBhbnNbcnRdID0gbWluKGFuc1tydF0sIGRpc3Rbdl0gKyB3KTsKICAgICAgICAgICAgICAgIGFuc1tyb290W3ZdXSA9IG1pbihhbnNbcm9vdFt2XV0sIGRpc3Rbdl0gKyB3KTsKICAgICAgICAgICAgfQoKICAgICAgICAgICAgaWYgKHcgPCBkaXN0W3ZdKSB7CiAgICAgICAgICAgICAgICBkaXN0W3ZdID0gdzsKICAgICAgICAgICAgICAgIHJvb3Rbdl0gPSBydDsKICAgICAgICAgICAgICAgIFEucHVzaCh7dywge3YsIHJ0fX0pOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gazsgaSsrKSB7CiAgICAgICAgaW50IHUgPSBEQltpXTsKICAgICAgICBpZiAoYW5zW3VdID09IGluZikgY291dCA8PCAiLTFcbiI7CiAgICAgICAgZWxzZSBjb3V0IDw8IGFuc1t1XSA8PCAiXG4iOwogICAgfQp9Cn07CnNpZ25lZCBtYWluKCkgewogICAgY2luLnRpZShOVUxMKS0+c3luY193aXRoX3N0ZGlvKGZhbHNlKTsgY291dC50aWUoTlVMTCk7CiAgICBpZiAoaWZzdHJlYW0oIkRCLklOUCIpKSB7CiAgICAgICAgZnJlb3BlbigiREIuSU5QIiwgInIiLCBzdGRpbik7CiAgICAgICAgZnJlb3BlbigiREIuT1VUIiwgInciLCBzdGRvdXQpOwogICAgfQogICAgY2luID4+IG4gPj4gbSA+PiBrOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbTsgaSsrKSB7CiAgICAgICAgaW50IHUsIHYsIHc7IGNpbiA+PiB1ID4+IHYgPj4gdzsKICAgICAgICBHW3VdLnB1c2hfYmFjayh7diwgd30pOwogICAgICAgIEdbdl0ucHVzaF9iYWNrKHt1LCB3fSk7CiAgICB9CiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBrOyBpKyspewogICAgICAgIGNpbiA+PiBEQltpXTsKICAgICAgICBpc0RCW0RCW2ldXSA9IDEgOwogICAgfQovLyAgICBpZiAobiA8PSAyMDApIHJldHVybiBzdWIxOjpzb2x2ZSgpLCAwOwogICAgcmV0dXJuIHN1YmZ1bGw6OnNvbHZlKCksIDA7CiAgICByZXR1cm4gMDsKfQo=