#include using namespace std; using uint = unsigned int; using lint = long long int; using ulint = unsigned long long int; template using V = vector; template using VV = V< V >; template void assign(V& v, int n, const U& a) { v.assign(n, a); } template void assign(V& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); } struct Edge { int to, cost; }; template V dijkstra(const VV& g, int s = 0) { V dist(g.size(), numeric_limits::max()); using P = pair; priority_queue, greater

> pque; pque.emplace(dist[s] = 0, s); while (!pque.empty()) { T d; int v; tie(d, v) = pque.top(); pque.pop(); if (d > dist[v]) continue; for (const auto& e : g[v]) { if (dist[e.to] <= dist[v] + e.cost) continue; pque.emplace(dist[e.to] = dist[v] + e.cost, e.to); } } return dist; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int n, m, l; cin >> n >> m >> l, --l; V<> t(n); for (int i = 0; i < n; ++i) cin >> t[i]; VV g(n); for (int i = 0; i < m; ++i) { int a, b, c; cin >> a >> b >> c, --a, --b; g[a].emplace_back(Edge{b, c}); g[b].emplace_back(Edge{a, c}); } auto dl = dijkstra(g, l); lint res = 9e18; for (int v = 0; v < n; ++v) { auto d = dijkstra(g, v); lint curr = 2 * inner_product(begin(t), end(t), begin(d), 0LL); int mx = 0; for (int u = 0; u < n; ++u) if (t[u] > 0) { mx = max(mx, d[u] - dl[u]); } curr -= mx; res = min(res, curr); } cout << res << '\n'; }