#!/usr/bin/env python3 #fileencoding: utf-8 N = int(input()) S = [int(input()) for i in range(N)] costs = [[int(j) for j in input().strip().split(" ")] for i in range(int(input()))] cost_map = [[1<<31]*N for i in range(N)] for cost in costs: cost_map[cost[0]][cost[1]] = cost[2] cost_map[cost[1]][cost[0]] = cost[2] # warshall_froyd for i in range(N): # 経由 for j in range(N): # start for k in range(N): # goal if j == k: cost_map[j][k] = 0 else: cost_map[j][k] = min(cost_map[j][k],cost_map[j][i]+cost_map[i][k]) result = 1000000 for i in range(1,N-1): for j in range(1,N-1): if i != j: result = min(result, cost_map[0][i] + cost_map[i][j] + cost_map[j][N-1] + S[i] + S[j]) print(result)