其它9个点都对。
代码在此:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn=30000+1000,maxm=150000+1000;
int head[maxn],dist[maxn],n,m,s=1,index=0;
bool check[maxn];
queue <int> q;
struct lu{
int to,next,weight;
}road[maxm];
void add(int u,int v,int w)
{
road[index].to=v;
road[index].next=head[u];
road[index].weight=w;
head[u]=index;
index++;
}
void spfa()
{
memset(check,0,sizeof(check));
dist[s]=0;
q.push(s);
check[s]=true;
while(!q.empty())
{
int top=q.front();
q.pop();
check[top]=false;
for(int i=head[top];i!=-1;i=road[i].next)
{
if(dist[top]+road[i].weight<dist[road[i].to])
{
dist[road[i].to]=dist[top]+road[i].weight;
if(!check[road[i].to])
{
q.push(road[i].to);
check[road[i].to]=true;
}
}
}
}
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
dist[i]=99999999;
head[i]=-1;
}
for(int i=1;i<=m;i++)
{
int u,v,w;
scanf("%d%d%d",&u,&v,&w);
add(u,v,w);
add(v,u,w);
}
spfa();
printf("%d\n",dist[n]);
return 0;
}