hdu 2066 一个人的旅行
#include<stdio.h> int inf = 0x7fffffff; int map[1024][1024],des[1024],dis[1024],s,max,t,d,a[1024],b[1024]; int Dijkstra( ) { ++max; for( int i = 1; i <= d; ++i ) map[b[i]][max] = map[max][b[i]] = 0; dis[0] = 0; for( int i = 0; i <= max; ++i ) { int min = inf,pos = -1,t; for( int j = 0; j <= max; ++j )//寻找当前的最短路 { if( !des[j] ) if( dis[j] != inf ) if( dis[j] < min ) { min = dis[j]; pos = j; } } des[pos] = 1; for( int j = 0; j <= max; ++j )//更新于当前最短路相连的节点 { if( !des[j] ) if( map[pos][j] != inf ) if( ( t = dis[pos] + map[pos][j] ) < dis[j] ) { dis[j] = t; } } } int min = inf; for( int i = 1; i <= d; ++i ) min = min < dis[b[i]] ? min :dis[b[i]]; return min; } int main( ) { while( scanf( "%d%d%d",&t,&s,&d ) != EOF ) { for( int i = 0; i <= 1010; ++i ) { for( int j = 0; j <= 1010; ++j ) map[i][j] = inf; des[i] = 0; dis[i] = inf; } for( int i = 1; i <= t; ++i ) { int x,y,v; scanf( "%d%d%d",&x,&y,&v ); if( v < map[x][y] )//一直wa的所在地 map[x][y] = map[y][x] = v; y = y > x ? y: x; max = max > y ?max: y; } for( int i = 1; i <= s; ++i ) { scanf( "%d",&a[i] ); map[0][a[i]] = map[a[i]][0] = 0; } for( int j = 1; j <= d; ++j ) { scanf( "%d",&b[j] ); } printf( "%d\n",Dijkstra() ); } return 0; }
本人还是新手 ,转载请注明来自Lvsi‘s home