#include typedef long long ll; #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REP(i,a) FOR(i,0,a) using namespace std; const int MAX_N=2e3; const ll INF=1e18; struct edge{ int to; ll cst; edge(int t=-1,ll c=0):to(t),cst(c){} }; vector G[MAX_N]; int N,M,L; ll t[MAX_N]; ll dst[MAX_N][MAX_N]; typedef pair P; void dijk(int s){ REP(v,N)dst[s][v]=INF; dst[s][s]=0; priority_queue,greater

> pque; pque.push(P(0,s)); while(!pque.empty()){ P p=pque.top(); pque.pop(); int v=p.second; if(p.first>dst[s][v])continue; for(auto e:G[v]){ if(dst[s][e.to]>dst[s][v]+e.cst){ dst[s][e.to]=dst[s][v]+e.cst; pque.push(P(dst[s][e.to],e.to)); } } } } int main(){ cin>>N>>M>>L; L--; REP(i,N)cin>>t[i]; REP(i,M){ int a,b; ll c; cin>>a>>b>>c; a--; b--; G[a].push_back(edge(b,c)); G[b].push_back(edge(a,c)); } REP(i,N){ dijk(i); } ll ans=INF; REP(v,N){ ll sm=0; REP(i,N){ sm+=2*t[i]*dst[v][i]; } REP(u,N){ if(t[u]>0){ ans=min(ans,sm+dst[L][u]-dst[u][v]); } } } int flg=0; REP(v,N){ if(t[v]>0){ flg++; } } if(flg==1){ ans=0; } cout<