标签:des blog http io ar os for sp strong
Description
Input
Output
Sample Input
Sample Output
#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> #define INF 1000000000 using namespace std; int w[1000+10][1000+10]; int d[1000+10]; int v[1000+10]; int n,t,ans; void dij() { memset(v,0,sizeof(v)); for(int i=0;i<=n;i++) {d[i]=(i==0?0:INF);} for(int i=0;i<=n;i++) { int x,m=INF; for(int y=0;y<=n;y++) if(!v[y]&&d[y]<=m) m=d[x=y]; v[x]=1; for(int y=0;y<=n;y++) { if(d[y]>d[x]+w[x][y]) { d[y]=d[x]+w[x][y]; } } } } int main() { int i,j,m; int f,to,time; while(scanf("%d%d%d",&n,&m,&t)!=EOF) { for(i=0;i<=n;i++) { for(j=0;j<=n;j++) { w[i][j]=INF; } } while(m--) { scanf("%d%d%d",&f,&to,&time); if(time<w[f][to]) w[f][to]=time; } int coun; scanf("%d",&coun); while(coun--) { int temp; scanf("%d",&temp); w[0][temp]=0; } dij(); if(d[t]<INF) printf("%d\n",d[t]); else printf("-1\n"); } return 0; }
HDU 2680 Choose the best route(最短路)
标签:des blog http io ar os for sp strong
原文地址:http://www.cnblogs.com/sola1994/p/4074301.html