#include using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define all(x) (x).begin(),(x).end() #define foreach(u,v) for(auto (u) : (v)) #define pb push_back #define mp make_pair #define mt make_tuple #define int long long typedef long long ll; typedef pair pii; typedef vector vi; typedef vector vvi; typedef pair pll; typedef vector vl; const int inf = 1e9; const ll linf = 1LL<<60; const ll mod = 1e9 + 7; const double eps = 1e-9; /* */ int n, m, l, t[2000]; vector es[2000]; ll d[2000][2000]; void dijkstra(int s) { priority_queue, greater> que; fill(d[s], d[s]+n, linf); d[s][s] = 0; que.push(mp(0LL, s)); while(!que.empty()){ pll p = que.top(); que.pop(); if(d[s][p.second] < p.first) continue; foreach(e, es[p.second]){ if(d[s][e.first] > d[s][p.second] + e.second){ d[s][e.first] = d[s][p.second] + e.second; que.push(mp(d[s][e.first], e.first)); } } } } signed main() { cin >> n >> m >> l; int cnt = 0; rep(i, n){ cin >> t[i]; if(t[i] > 0) cnt++; } l--; rep(i, m){ int a, b, c; cin >> a >> b >> c; a--; b--; es[a].pb(mp(b, c)); es[b].pb(mp(a, c)); } if(cnt == 1){ cout << 0 << endl; return 0; } rep(i, n){ dijkstra(i); } ll ans = linf; rep(i, n){ ll tmp = 0; rep(j, n){ tmp += 2*t[j]*d[i][j]; } rep(j, n){ if(t[j] > 0) ans = min(ans, tmp+d[l][j]-d[i][j]); } } cout << ans << endl; /* rep(i, n){ rep(j, n){ cout << d[i][j] << " "; } cout << endl; } */ return 0; }