int spfa()
{
int vis[N];
int dis[N];
memset(vis,0,sizeof(vis));
for(int i=1;i<=n;i++)
dis[i]=inf;
queue<int>myqueue;
while(!myqueue.empty())myqueue.pop();
vis[1]=1;
dis[1]=0;
myqueue.push(1);
while(!myqueue.empty())
{
int top=myqueue.front();
vis[top]=0;
myqueue.pop();
for(int i=0;i<edge[top].size();i++)
{
int v=edge[top][i].v;
int len=edge[top][i].len;
if(dis[v]>dis[top]+len)
{
dis[v]=dis[top]+len;
if(!vis[v])
{
vis[v]=1;
myqueue.push(v);
}
}
}
}
return dis[n];
}
SPFA
最新推荐文章于 2012-10-31 11:08:03 发布