0x3f -> 0x3f3f3f3f
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 510;
int g[N][N];
int d[N];
bool st[N];
int n, m;
int Dijkstra()
{
memset(d,0x3f,sizeof d);
d[1] = 0;
for(int i = 0;i < n;i++)
{
int u = -1;
for(int j = 1; j<= n;j++)
{
if(((u == -1) || d[j] < d[u]) && !st[j])
{
u = j;
}
}
st[u] = true;
for(int k = 1; k <= n;k++)
{
d[k] = min(g[u][k] + d[u],d[k]);
}
}
if(d[n]==0x3f3f3f3f) return -1; //如果第n个点路径为无穷大即不存在最低路径
return d[n];
}
int main()
{
memset(g,0x3f,sizeof g);
cin >> n >> m;
int a, b, c;
for(int i = 0;i < m;i++)
{
cin >> a>> b>> c;
g[a][b] = min(g[a][b],c);
}
cout << Dijkstra();
return 0;
}