N = int(input()) S = [int(input()) for i in range(N)] M = int(input()) INF = float('inf') costs = [[INF]*N for i in range(N)] for i in range(N): costs[i][i] = 0 for _ in range(M): a, b, c = map(int, input().split()) costs[a][b] = c costs[b][a] = c for k in range(N): for i in range(N): for j in range(N): costs[i][j] = min(costs[i][j], costs[i][k] + costs[k][j]) min_cost = INF for i in range(1, N - 1): for j in range(1, N - 1): if i == j: continue total_cost = costs[0][i] + costs[i][j] + costs[j][N - 1] + S[i] + S[j] if min_cost > total_cost : min_cost = total_cost print(min_cost)