INF = 1 << 60 N = int(input()) S = [int(input()) for _ in range(N)] M = int(input()) dp = [[INF] * N for _ in range(N)] for i in range(N): dp[i][i] = 0 for _ in range(M): A, B, C = map(int, input().split()) dp[A][B] = dp[B][A] = C # ワーシャル・フロイド法 for k in range(N): for i in range(N): for j in range(N): dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]) ans = INF # 0 - i - j - N-1 (i, j に滞在) for i in range(1, N-1): for j in range(1, N-1): if i == j: continue ans = min(ans, dp[0][i] + S[i] + dp[i][j] + S[j] + dp[j][N-1]) print(ans)