#include #include using namespace atcoder; using mint = modint1000000007; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 100000000000000000 vector get(vector> E,vector a,vector b,vector c,int s){ int n = E.size(); vector d(n,Inf); d[s] = 0; priority_queue,vector>,greater>> Q; Q.emplace(0,s); while(Q.size()>0){ long long D = Q.top().first; int u = Q.top().second; Q.pop(); if(d[u]!=D)continue; rep(i,E[u].size()){ int ind = E[u][i]; int v = a[ind] ^ b[ind] ^ u; long long DD = D + c[ind]; if(DD < d[v]){ Q.emplace(DD,v); d[v] = DD; } } } return d; } int main() { int N,M,L; cin>>N>>M>>L; L--; vector t(N); rep(i,N)cin>>t[i]; vector> E(N); vector a(M),b(M),c(M); rep(i,M){ cin>>a[i]>>b[i]>>c[i]; a[i]--,b[i]--; E[a[i]].push_back(i); E[b[i]].push_back(i); } set s; rep(i,N){ if(t[i]>0)s.insert(i); } if(s.size()==1){ cout<<0<> d(N); rep(i,N){ d[i] = get(E,a,b,c,i); } long long ans = Inf; rep(i,N){ long long sum = 0; rep(j,N){ sum += t[j] * d[i][j] * 2; } long long mi = d[i][L]; rep(j,N){ if(t[j]>0){ mi = min(mi,d[L][j] + d[j][i] - d[i][j]*2); } } sum += mi; ans = min(ans,sum); } cout<