#!/usr/bin/env python3 # -*- coding: utf-8 -*- import array import itertools INF = 10 ** 9 class WarshallFloyd(object): def __init__(self, max_v, edges): self.max_v = max_v self.dist = edges for v in range(max_v): self.dist[v][v] = 0 def compute(self): for v, u, w in itertools.product(range(self.max_v), repeat=3): new_length = self.dist[u][v] + self.dist[v][w] self.dist[u][w] = min(self.dist[u][w], new_length) return self.dist def main(): n = int(input()) stay_costs = array.array("I", (int(input()) for _ in range(n))) m = int(input()) edges = [array.array("L", (INF for _ in range(n))) for _ in range(n)] for _ in range(m): a, b, c = map(int, input().split()) edges[a][b] = c edges[b][a] = c wf = WarshallFloyd(n, edges) move_costs = wf.compute() answer = INF for u0, v0 in itertools.combinations(range(1, n - 1), 2): for u, v in [(u0, v0), (v0, u0)]: move_cost = move_costs[0][u] + \ move_costs[u][v] + move_costs[v][n - 1] stay_cost = stay_costs[u] + stay_costs[v] answer = min(answer, move_cost + stay_cost) print(answer) if __name__ == '__main__': main()