#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
#define MAXN 1005
#define INF 0x3f3f3f3f
int visit[MAXN];
int Edge[MAXN][MAXN];
int dist[MAXN];
int s[MAXN],e[MAXN];
void Dijkstra(int v,int n)
{
for(int i=1; i<=n; i++)
{
visit[i] = 0;
dist[i] = Edge[v][i];
}
visit[v] = 1;
for(int i=1; i<=n; i++)
{
int MIN = INF;
int u = v;
for(int j=1; j<=n; j++)
if(!visit[j]&&dist[j]<MIN)
{
u = j;
MIN = dist[j];
}
visit[u] = 1;
for(int k=1; k<=n; k++)
if(dist[u]+Edge[u][k]<dist[k])
dist[k] = dist[u]+Edge[u][k];
}
}
int main()
{
int m,st,en,u,v,t,ans;
while(~scanf("%d%d%d",&m,&st,&en))
{
int n = 0,ans = INF;
for(int i=1; i<MAXN; i++)
for(int j=1; j<MAXN; j++)
{
if(i==j)
Edge[i][j] = 0;
else
Edge[i][j] = INF;
}
for(int i=1; i<=m; i++)
{
scanf("%d%d%d",&u,&v,&t);
if(t<Edge[u][v])
Edge[u][v] = Edge[v][u] = t;
n = max(n,max(u,v));
}
for(int i=0; i<st; i++)
scanf("%d",&s[i]);
for(int i=0; i<en; i++)
scanf("%d",&e[i]);
for(int i=0; i<st; i++)
{
Dijkstra(s[i],n);
for(int j=0; j<en; j++)
{
//printf("%d ",dist[e[j]]);
ans = min(ans,dist[e[j]]);
}
// printf("\n");
}
printf("%d\n",ans);
}
return 0;
}
hdu_2066 一个人的旅行
最新推荐文章于 2021-08-01 09:42:17 发布