#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define MT make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)<; using vi = vector; using vll = vector; typedef long long Weight; struct Edge { int from, to; Weight wei; Edge(int from_, int to_, Weight wei_) :from(from_), to(to_), wei(wei_) {} }; typedef vector Edges; typedef vector Graph; const Weight INFW = numeric_limits::max(); vector dijkstra(const Graph &G, int src) { typedef pair pwi; priority_queue, greater> pq; pq.push(mp(0, src)); int V = (int)G.size(); vector res(V, -1); while (pq.size()) { auto p = pq.top(); pq.pop(); Weight d = p.first; int v = p.second; if (res[v] > -1)continue; res[v] = d; for (const auto &edge : G[v]) { int to = edge.to; Weight wei = edge.wei; pq.push(make_pair(d + wei, to)); } } return res; } int N, M, L; void solve() { cin >> N >> M >> L; --L; vi T(N); Graph G(N); rep(i, N)cin >> T[i]; rep(i, M) { int a, b, c; cin >> a >> b >> c; --a; --b; G[a].emplace_back(a, b, c); G[b].emplace_back(b, a, c); } vll dl = dijkstra(G, L); ll ans = INFW; if (accumulate(all(T), 0ll) <= 1)ans = 0; rep(i, N) { vll d = dijkstra(G, i); ll sm = 0, mi = INFW; rep(j, N) { sm += d[j] * 2 * T[j]; if (T[j] > 0)smin(mi, dl[j] - d[j]); } sm += mi; smin(ans, sm); } cout << ans << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); solve(); return 0; }