#include using namespace std; #define rep(i, n) for (int i=0; i P; int N, M, L; int t[2010]; vector

G[2010]; vector> D; vector dijkstra(int s) { priority_queue, greater

> q; vector d(N); rep(i, N) d[i] = 1000000000000; d[s] = 0; q.push(P(0, s)); while (!q.empty()) { P p = q.top(); q.pop(); int v = p.second; if (d[v]d[v]+w) { d[nv] = d[v]+w; q.push(P(d[nv], nv)); } } } return d; } signed main() { //ループ変数が被っていないか? //制約を確認しているか? //変数のtypoがないか? cin.tie(0); ios::sync_with_stdio(false); cin >> N >> M >> L; int s = 0; rep(i, N) { cin >> t[i]; s += t[i]; } rep(i, N) { if (t[i]==s) { cout << 0 << endl; exit(0); } } rep(i, M) { int a, b, c; cin >> a >> b >> c; G[a-1].pb(P(b-1, c)); G[b-1].pb(P(a-1, c)); } rep(i, N) D.pb(dijkstra(i)); int ans = 1000000000000000000; rep(i, N) { int base = 0; rep(j, N) base += 2*t[j]*D[i][j]; rep(j, N) { int cand = base+D[L-1][j]+D[j][i]; if (t[j]>=1) cand -= 2*D[i][j]; ans = min(ans, cand); } } cout << ans << endl; }