Title: Click to open link
Code:
#include <stdio.h> #include <algorithm> #define INF 0x3f3f3f3fusing namespace Std;int a1[1010];int b1[1010]; int Cost[1010][1010],d[1010];bool used[1010];int m,n,p;void distr (int x) {for (int i=1;i<1010;i++) {D[i]=INF;used[i] =false;} D[x]=0;while (true) {int v=-1;for (int u=1;u<1010;u++) if (!used[u]&& (v==-1| | D[U]<D[V]) v=u;used[v]=true;if (v==-1) break;for (int u=1;u<1010;u++) d[u]=min (D[u],d[v]+cost[v][u]);}} int main () {while (~scanf ("%d%d%d", &m,&n,&p)) {int i,j;int a,b,c;for (i=1;i<1010;i++) for (j=1;j <1010;j++) cost[i][j]=inf;for (i=0;i<m;i++) {scanf ("%d%d%d", &a,&b,&c), if (C<cost[a][b]) { cost[a][b]=c; Cost[b][a]=c;}} C=inf;for (i=0;i<n;i++) scanf ("%d", &a1[i]); for (i=0;i<p;i++) scanf ("%d", &b1[i]); for (i=0;i<n;i++) { distr (a1[i]); for (j=0;j<p;j++) { if (d[b1[j]]<c) c=d[b1[j];} } printf ("%d\n", c);} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Hdu OJ 20,661-person trip