#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N, M, L; cin >> N >> M >> L; --L; vector t(N); for(int i = 0; i < N; ++i) cin >> t[i]; using edge = pair; vector> g(N); for(int i = 0; i < M; ++i){ int a, b, c; cin >> a >> b >> c; --a, --b; g[a].emplace_back(b, c); g[b].emplace_back(a, c); } constexpr ll inf = 1e+17; vector> dist(N); for(int s = 0; s < N; ++s){ vector dp(N, inf); dp[s] = 0; using node = pair; priority_queue, greater> que; que.emplace(0, s); while(!que.empty()){ auto [d, from] = que.top(); que.pop(); if(d > dp[from]) continue; for(auto& [to, cost] : g[from]){ if(chmin(dp[to], dp[from] + cost)){ que.emplace(dp[to], to); } } } dist[s] = dp; } ll ans = 7e+18; for(int s = 0; s < N; ++s){ ll sum = 0; if(s == L){ for(int i = 0; i < N; ++i){ sum += dist[s][i] * t[i] * 2; } chmin(ans, sum); } else if(t[L] > 0){ t[L] -= 1; sum += dist[s][L]; for(int i = 0; i < N; ++i){ sum += dist[s][i] * t[i] * 2; } t[L] += 1; chmin(ans, sum); } else{ for(int i = 0; i < N; ++i){ sum += dist[s][i] * t[i] * 2; } chmin(ans, sum + dist[L][s]); for(int i = 0; i < N; ++i){ if(t[i] > 0){ sum -= dist[s][i] * 2; sum += dist[L][i] + dist[i][s]; chmin(ans, sum); sum += dist[s][i] * 2; sum -= dist[L][i] + dist[i][s]; } } } } cout << ans << endl; return 0; }