from heapq import * from collections import defaultdict import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def main(): to=defaultdict(list) n=II() cost_node=[II() for _ in range(n)] m=II() for _ in range(m): a,b,c=MI() to[a].append([b,c]) to[b].append([a,c]) costs=[[-1]*n for _ in range(3)] hp0=[] hp1=[] hp2=[] heappush(hp0,[0,0]) cnt=0 while hp0 and cnt