def warshall_floyd(d): for k in range(N): for i in range(N): for j in range(N): d[i][j] = min(d[i][j], d[i][k] + d[k][j]) return d N = int(input()) S = [int(input()) for _ in range(N)] M = int(input()) dist = [[float("inf") for _ in range(N)] for _ in range(N)] for i in range(N): dist[i][i] = 0 for i in range(M): x, y, z = map(int, input().split()) dist[x][y] = z dist[y][x] = z dist = warshall_floyd(dist) cost = float("inf") for i in range(1, N - 1): for j in range(1, N - 1): if i == j: continue cost = min(cost, dist[0][i] + dist[i][j] + dist[j][N - 1] + S[i] + S[j]) print(cost)