#include using namespace std; const int kINF = 1 << 25; const int kMAX_N = 60; const int kMAX_M = kMAX_N * (kMAX_N - 1) / 2; int N, M; int S[kMAX_N]; int A[kMAX_M], B[kMAX_M], C[kMAX_M]; int cost[kMAX_N][kMAX_N]; void Solve() { fill((int* )cost, (int* )(cost + kMAX_N), kINF); for (int i = 0; i < N; i++) { cost[i][i] = 0; } for (int i = 0; i < M; i++) { cost[A[i]][B[i]] = cost[B[i]][A[i]] = C[i]; } for (int k = 0; k < N; k++) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]); } } } int answer = kINF; for (int node1 = 1; node1 < N - 1; node1++) { for (int node2 = 1; node2 < N - 1; node2++) { if (node1 == node2) continue; answer = min(answer, cost[0][node1] + cost[node1][node2] + cost[node2][N - 1] + S[node1] + S[node2]); } } cout << answer << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; for (int i = 0; i < N; i++) { cin >> S[i]; } cin >> M; for (int i = 0; i < M; i++) { cin >> A[i] >> B[i] >> C[i]; } Solve(); return 0; }