#include "bits/stdc++.h" #define ALL(x) x.begin(), x.end() #define LEN(x) (int)x.size() #define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0) using namespace std; typedef int64_t i64; typedef pair pii; templateinline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;} templateinline bool chmin(A &a, const B &b){return b G[2005]; vector dist[2005]; void dijkstra(int src, vector &dist) { priority_queue< pii, vector, greater > pq; dist.assign(N, LINF); pq.emplace(0, src); dist[src] = 0; while(!pq.empty()) { const i64 c = pq.top().first; const int u = pq.top().second; pq.pop(); if (dist[u] < c) continue; for (const auto &e : G[u]) { const i64 nc = c + e.first; const int nxt = e.second; if (chmin(dist[nxt], nc)) pq.emplace(nc, nxt); } } return; } signed main() { iostreamBooster(); cin >> N >> M >> L; --L; for (int i= 0; i < N; ++i) { cin >> t[i]; } for (int i = 0; i < M; ++i) { int a, b, c; cin >> a >> b >> c; --a, --b; G[a].emplace_back(c, b); G[b].emplace_back(c, a); } for (int src = 0; src < N; ++src) { dijkstra(src, dist[src]); } i64 ans = LINF; for (int goal = 0; goal < N; ++goal) { i64 sum = 0; for (int u = 0; u < N; ++u) sum += 2*dist[goal][u] * t[u]; i64 hoge = sum; for (int k = 0; k < N; ++k) { if (t[k] <= 0) continue; chmin(hoge, sum + dist[L][k] - dist[k][goal]); } chmin(ans, hoge); } cout << ans << endl; return 0; }