标签:style blog http io color os ar java for
7 11 5 4
2 4 2
1 4 3
7 2 2
3 4 3
5 7 5
7 3 3
6 1 1
6 3 4
2 4 3
5 6 3
7 2 1
7
SPFA。。。
#include<iostream> #include<cstdlib> #include<cstdio> using namespace std; int p[3000][3000]; int p1,p2; int head,tail,T,C,start,end; int now,nowstep; int queue[620005]; int least[3000]; int main() { cin>>T>>C>>start>>end; for (int i=1;i<=T;i++) for (int j=1;j<=T;j++) p[i][j]=598460606; for (int i=1;i<=C;i++) { cin>>p1>>p2; cin>>p[p1][p2]; p[p2][p1]=p[p1][p2]; } for (int i=1;i<=T;i++) least[i]=598460606; head=1;tail=1;queue[1]=start;least[start]=0; while (head<=tail) { now=queue[head]; for (int i=1;i<=T;i++) { if ( least[i]> (least[now]+p[now][i]) ) { least[i]=least[now]+p[now][i]; tail++; queue[tail]=i; } } head++; } cout<<least[end]<<endl; return 0; }
标签:style blog http io color os ar java for
原文地址:http://www.cnblogs.com/seekdreamer/p/4057451.html