#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; struct Node { int v; ll cost; Node(int v = -1, ll cost = -1) { this->v = v; this->cost = cost; } bool operator>(const Node &n) const { return cost > n.cost; } }; struct Edge { int to; ll cost; Edge(int to, int cost) { this->to = to; this->cost = cost; } }; ll g_cost[2010][2010]; int main() { int N, M, L; cin >> N >> M >> L; int T[N]; for (int i = 0; i < N; ++i) { cin >> T[i]; } memset(g_cost, 0, sizeof(g_cost)); vector G[N + 1]; for (int i = 0; i < M; ++i) { ll a, b, c; cin >> a >> b >> c; G[a].push_back(Edge(b, c)); G[b].push_back(Edge(a, c)); } for (int v = 1; v <= N; ++v) { priority_queue , greater> pque; bool visited[N + 1]; memset(visited, false, sizeof(visited)); pque.push(Node(v, 0)); while (not pque.empty()) { Node node = pque.top(); pque.pop(); if (visited[node.v]) continue; visited[node.v] = true; g_cost[v][node.v] = node.cost; for (Edge &e : G[node.v]) { ll n_cost = node.cost + e.cost; pque.push(Node(e.to, n_cost)); } } } ll ans = LLONG_MAX; for (int v = 1; v <= N; ++v) { ll base_cost = 0; for (int u = 1; u <= N; ++u) { base_cost += T[u - 1] * (2 * g_cost[u][v]); } ll min_cost = LLONG_MAX; for (int u = 1; u <= N; ++u) { if (T[u - 1] == 0) continue; ll new_cost = base_cost; new_cost -= 2 * g_cost[u][v]; new_cost += g_cost[L][u] + g_cost[u][v]; min_cost = min(min_cost, new_cost); } ans = min(ans, min_cost); } cout << ans << endl; return 0; }