int SPFA()
{
int i,temp;
deque<int>Q;
bool flag[1001];//是否在队列中
int dist[1001];
memset(dist,63,sizeof(dist));
memset(flag,0,sizeof(flag));
flag[1]=1;
Q.push_back(1);
dist[1]=0;
while(!Q.empty())
{
temp=Q.at(0);
Q.pop_front();
for(i=1;i<=N;i++)
{
if(dist[i]>dist[temp]+map[temp][i])
{
dist[i]=dist[temp]+map[temp][i];
if(flag[i]==0)
{
flag[i]=1;
Q.push_back(i);
}
}
}
flag[temp]=0;
}
return dist[N];
}
+上进队次数可以判负环