#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>using namespace STD;Const intinf=1024x768;Const intn=1024x768;intN,m,vis[n],edge[n][n],dist[n];voidDijkstra (intV0) {intI,j,k,u,minx; for(i=1; i<=n; i++) {Dist[i]=edge[v0][i]; vis[i]=0; } vis[v0]=1; dist[v0]=0; for(i=1; i<n; i++) {minx=inf,u=v0; for(j=1; j<=n; J + +) {if(!vis[j]&&dist[j]<minx) {MINX=DIST[J]; U=j; }} vis[u]=1; for(k=1; k<=n; k++) {if(!vis[k]&&edge[u][k]<inf&&dist[u]+edge[u][k]<dist[k]) dist[k]=dist[u]+edge[u][k]; } }}intMain () {intI,j,k,u,v,w,t,ans,a,s; while(~scanf("%d%d%d", &n,&m,&s)) {memset(Edge,0,sizeof(Edge)); for(i=0; i<m; i++) {scanf("%d%d%d", &u,&v,&w);if(edge[v][u]==0|| EDGE[V][U]>W) Edge[v][u]=w; } for(i=1; i<=n; i++) for(j=1; j<=n; J + +) {if(I==J) edge[i][j]=0;Else if(edge[i][j]==0) Edge[i][j]=inf; }scanf("%d", &w); Ans=inf; Dijkstra (s); for(i=0; i<w; i++) {scanf("%d", &a); Ans=min (Ans,dist[a]); }if(Ans<inf)printf("%d\n", ans);Else printf(" -1\n"); }return 0;}
HDU 2680 Choose the best route