#include "bits/stdc++.h" using namespace std; void solve() { int n, m, l; cin >> n >> m >> l; l--; vector ts(n), ds(n, 1<<20); for (int i = 0; i < n; i++) { cin >> ts[i]; } vector> g[n]; while(m--) { int u, v, w; cin >> u >> v >> w; u--, v--; g[u].emplace_back(v, w); g[v].emplace_back(u, w); } priority_queue, vector>, greater>> pq; pq.push(make_pair(0, l)); ds[l] = 0; while (!pq.empty()) { auto p = pq.top(); pq.pop(); int v = p.second, x = p.first; for (auto np : g[v]) { int nv = np.first, nw = np.second; if (ds[nv] <= x + nw) continue; ds[nv] = x + nw; pq.push(make_pair(ds[nv], nv)); } } long ans = LONG_MAX; for (int s = 0; s < n; s++) { vector d(n, 1<<20); pq.push(make_pair(0, s)); d[s] = 0; while(!pq.empty()) { auto p = pq.top(); pq.pop(); int v = p.second, x = p.first; for (auto np : g[v]) { int nv = np.first, nw = np.second; if (d[nv] <= x + nw) continue; d[nv] = x + nw; pq.push(make_pair(d[nv], nv)); } } /* for (int dx : d){ cout << dx << ' ';} cout << endl; */ long res = 0; int p = 0; for (int j = 0; j < n; j++) { res += 2*ts[j]*d[j]; p = min(p, ds[j] - d[j]); } ans = min(ans, res+p); //cout << res << ' ' << p << endl; } cout << ans << endl; } int main(void) { solve(); //cout << "yui(*-v・)yui" << endl; return 0; }