#include #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair ; using pll = pair; constexpr int INF = 1e9; constexpr long long LINF = 1e17; constexpr int MOD = 1000000007; int n = 2005,m,l; vector>> graph(n,vector>()); vector dijkstra(ll start){ vector shortest(n); vector visited(n,false); priority_queue,vector>,greater>> pq; pq.push(make_pair(0,start)); while (!pq.empty()){ pair now = pq.top(); pq.pop(); ll cost,node; tie(cost,node) = now; if(visited[node]){ continue; }else{ shortest[node] = cost; visited[node] = true; for(pair next:graph[node]){ ll next_cost,next_node; tie(next_cost,next_node) = next; pq.push(make_pair(cost+next_cost,next_node)); } } } return shortest; } int main(){ cin >> n >>m >> l; --l; vector t(n); rep(i,n) cin >> t[i]; rep(i,m){ ll a,b,c; cin >>a >> b >> c; --a;--b; graph[a].push_back(pll(c,b)); graph[b].push_back(pll(c,a)); } vector disL = dijkstra(l); ll ans = LINF; rep(target,n){ vector dist = dijkstra(target); ll res = 0; rep(i,n){ res += 2 * dist[i] * t[i]; } ll mn = dist[l]; rep(i,n){ if(t[i] > 0){ mn = min(mn,disL[i]-dist[i]); } } if(res != 0) res += mn; ans = min(ans,res); } cout << ans << endl; return 0; }