#include #include #include std::vector dijkstra(int N, std::vector>> G, int s) { using P = std::pair; std::vector dist(N, INT64_MAX); std::priority_queue, std::greater

> q; dist.at(s) = 0; q.emplace(0, s); while (q.size()) { auto [c, v] = q.top(); q.pop(); if (dist.at(v) < c) continue; for (const auto& [t, cost] : G.at(v)) { if (dist.at(v) + cost < dist.at(t)) { dist.at(t) = dist.at(v) + cost; q.emplace(dist.at(t), t); } } } return dist; } int main() { int N, M, L; std::cin >> N >> M >> L; L--; std::vector T(N); for (int i = 0; i < N; i++) { std::cin >> T[i]; } std::vector>> G(N); for (int i = 0; i < M; i++) { int a, b, c; std::cin >> a >> b >> c; a--; b--; G.at(a).emplace_back(b, c); G.at(b).emplace_back(a, c); } std::vector> dist_all(N); for (int s = 0; s < N; s++) { dist_all.at(s) = dijkstra(N, G, s); } long ans = INT64_MAX; for (int t = 0; t < N; t++) { long s = 0; for (int x = 0; x < N; x++) { s += T[x] * 2 * dist_all[x][t]; } long m = 0; for (int x = 0; x < N; x++) { if (T[x] == 0) continue; long tmp_m = dist_all[t][x] - dist_all[L][x]; if (m < tmp_m) m = tmp_m; } if (ans > s - m) ans = s - m; } std::cout << ans << std::endl; }