正这搜一遍,倒这搜一遍
#include<iostream>
#include<cstdio>
using namespace std;
const int maxn=1e5+10;
int read()
{
int res=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
res=res*10+ch-'0';
ch=getchar();
}
return res*f;
}
int n,m,ans,v[maxn];
struct node
{
int a,x,y;
}e[maxn];
int main()
{
freopen("dwarf.in","r",stdin);
freopen("dwarf.out","w",stdout);
n=read();m=read();
for(int i=1;i<=n;i++) v[i]=read();
for(int i=1;i<=m;i++)
{
e[i].a=read();e[i].x=read();e[i].y=read();
v[e[i].a]=min(v[e[i].x]+v[e[i].y],v[e[i].a]);
}
for(int i=m;i>=1;i--) v[e[i].a]=min(v[e[i].x]+v[e[i].y],v[e[i].a]);
cout<<v[1]<<endl;
fclose(stdin);
fclose(stdout);
return 0;
}