SPFA+70
查看原帖
SPFA+70
297831
idgg007楼主2020/6/27 13:38

WA

#include<cstdio>
using namespace std;
int Cnt,Head[10005],N,M,Start,Dis[10005],Vis[10005];
int Q[10005],H,T;
struct edge{
	int Next;
	int To;
	int Dis;
}Edge[500005];
inline void AddEdge(register int From,register int To,register int D){
	Edge[++Cnt].Next=Head[From];
	Edge[Cnt].To=To;
	Edge[Cnt].Dis=D;
	Head[From]=Cnt;
}
int main(){
	scanf("%d%d%d",&N,&M,&Start);
	for(register int i=0;i<M;i++){
		int X,Y,W;
		scanf("%d%d%d",&X,&Y,&W);
		AddEdge(X,Y,W);
	}for(register int i=0;i<=N;i++)	Dis[i]=2147483647;
	Dis[Start]=0;
	Q[H]=Start;
	T++;
	Vis[Start]=1;
	while(H!=T){
		for(register int i=Head[Q[H]];i>0;i=Edge[i].Next){
			if(Dis[Edge[i].To]>Dis[Q[H]]+Edge[i].Dis){
				Dis[Edge[i].To]=Dis[Q[H]]+Edge[i].Dis;
				if(Vis[Edge[i].To]==0){
					Vis[Edge[i].To]=1;
					Q[T]=Edge[i].To;
					T++;
				}
			}
		}
		Vis[Q[H]]=0;
		H++;
	}for(register int i=1;i<=N;i++)	printf("%d ",Dis[i]);
	return 0;
}

SPFA好好的怎么会WA呢???

2020/6/27 13:38
加载中...