#include #define int long long using namespace std; typedef pair P; const int INF = 1e18; int n, m, l; int t[2000]; vector

G[2000]; int dist[2000][2000]; struct Dijkstra{ vector d; Dijkstra(int V){ d.resize(V, INF); } void calc(int s){ d[s] = 0; priority_queue, greater

> q; q.push(P(d[s], s)); while(!q.empty()){ P p = q.top(); q.pop(); int from = p.second; int cost = p.first; if(d[from] < cost) continue; for(auto e : G[from]){ int next = e.first; int newCost = cost + e.second; if(d[next] > newCost){ d[next] = newCost; q.push(P(newCost, next)); } } } } }; signed main(){ 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].push_back({b, c}); G[b].push_back({a, c}); } int cnt = 0; for(int i = 0; i < n; i++) if(t[i]) cnt++; if(cnt == 1){ cout << 0 << endl; return 0; } for(int i = 0; i < n; i++){ Dijkstra dk(n); dk.calc(i); for(int j = 0; j < n; j++){ dist[i][j] = dk.d[j]; } } int ans = INF; for(int i = 0; i < n; i++){ int tmp = dist[l][i]; for(int j = 0; j < n; j++){ tmp += t[j] * dist[i][j] * 2; } int MAX = 0; for(int j = 0; j < n; j++){ if(t[j] == 0) continue; MAX = max(MAX, dist[l][i] + dist[i][j] - dist[l][j]); } tmp -= MAX; ans = min(ans, tmp); } cout << ans << endl; }