n,m=map(int,input().split())
#节点cost,注意:起点和终点得设为0. ------------
c=list(map(int,input().split()))
c[0]=0
c[n-1]=0
#------------------------------------------
edges=[]
for i in range(m):
u,v,w=map(int,input().split())
edges.append((u,v,w))
#别忘记双向边
edges.append((v,u,w))
注意:起点和终点的cost得清洗为0(后面会具体解释)
而且本题是双向边,得两次edges.append( )