#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; long long int dist[2001][2001]; long long int t[2001]; int N, M, L; vector > adj[2001]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> M >> L; int cnt = 0; for (int i = 1; i <= N; i++) { cin >> t[i]; if (t[i] > 0) { cnt++; } } if (cnt <= 1) { cout << 0 << '\n'; return 0; } for (int i = 0; i < M; i++) { int a, b, c; cin >> a >> b >> c; adj[a].push_back(make_pair(b, c)); adj[b].push_back(make_pair(a, c)); } long long int res = 1e18; for (int i = 1; i <= N; i++) { fill(dist[i], dist[i] + 2001, 1e18); priority_queue , vector>, greater>> pque; dist[i][i] = 0; pque.push(make_pair(dist[i][i], i)); while (!pque.empty()) { int now = pque.top().second; if (dist[i][now] < pque.top().first) { pque.pop(); continue; } pque.pop(); for (auto it : adj[now]) { if (dist[i][it.first] > dist[i][now] + it.second) { dist[i][it.first] = dist[i][now] + it.second; pque.push(make_pair(dist[i][it.first], it.first)); } } } } /* for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { cout << dist[i][j] << ' '; } cout << '\n'; } */ for (int i = 1; i <= N; i++) { long long int sum = 0; for (int j = 1; j <= N; j++) { sum += (t[j] * (dist[i][j] + dist[j][i])); } long long int MIN = 1e18; for (int j = 1; j <= N; j++) { long long int temp = sum - (t[j] * 2 * dist[i][j]); temp += (dist[L][j] + dist[j][i] + (max(0LL,(t[j] - 1)) * (dist[i][j] + dist[j][i]))); //cout << i << ' ' << j << ' ' << temp << '\n'; MIN = min(MIN, temp); } //cout << i << ' ' << MIN << '\n'; res = min(res, MIN); } cout << res << '\n'; return 0; }