标签:
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
const int inf = 0x3f3f3f3f;
int T,S,D,n;
int MAP[1111][1111];
int vis[1111],cast[1111];
int s[1111],e[1111];
void Dijkstra()
{
int i,j,minn,pos;
memset(vis,0,sizeof(vis));
vis[0] = 1;
for(i = 0; i<=n; i++)
cast[i] = MAP[0][i];
for(i = 1; i<=n; i++)
{
minn = inf;
for(j = 1; j<=n; j++)
{
if(cast[j]<minn && !vis[j])
{
pos = j;
minn = cast[j];
}
}
vis[pos] = 1;
for(j = 1; j<=n; j++)
{
if(cast[pos]+MAP[pos][j]<cast[j] && !vis[j])
cast[j] = cast[pos]+MAP[pos][j];
}
}
}
int main()
{
int i,j,x,y,z;
while(cin >> T >> S >> D)
{
n = 0;
for(i = 0; i<1111; i++)
{
for(j = 0; j<1111; j++)
MAP[i][j] = inf;
MAP[i][i] = 0;
}
while(T--)
{
cin >> x >> y >> z;
n = max(max(n,x),y);
if(z<MAP[x][y])
MAP[x][y] = MAP[y][x] = z;
}
int minn = inf;
for(i = 0; i<S; i++)
{
cin >> s[i];
MAP[0][s[i]] = MAP[s[i]][0] = 0;
}
for(i = 0; i<D; i++)
cin >> e[i];
Dijkstra();
for(i = 0; i<D; i++)
minn = min(minn,cast[e[i]]);
cout << minn << endl;
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/2016zhanggang/p/5645232.html