n = int(input()) S = [int(input()) for _ in range(n)] m = int(input()) inf = 1 << 30 dist = [[inf] * n for _ in range(n)] for _ in range(m): a, b, c = map(int, input().split()) dist[a][b] = c dist[b][a] = c for i in range(n): dist[i][i] = 0 for k in range(n): for i in range(n): for j in range(n): dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]) ans = inf for i in range(1, n - 1): for j in range(1, n - 1): if i == j: continue tmp = dist[0][i] + dist[i][j] + dist[j][-1] + S[i] + S[j] ans = min(ans, tmp) print(ans)