就是dijkstra,只是他有很多个起点,那么我们只要用一个超级源点,让他到每一个七点的距离为0
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#define sf scanf
#define pf printf
#define scf(x) scanf("%lld",&x)
#define scff(x,y) scanf("%d%d",&x,&y)
#define scfff(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define prf(x) printf("%lld
",x)
#define mm(x,b) memset((x),(b),sizeof(x))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define de(x) cout<<#x<<"="<<x<<","
#define all(x) x.begin(),x.end()
#define dee(x) cout<<#x<<"="<<x<<"
"
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
typedef long long ll;
const ll mod=1e9+7;
const double eps=1e-8;
const ll inf=0x3f3f3f3f;
using namespace std;
const double pi=acos(-1.0);
const int N=1e5+10;
struct Node
{
ll v,dis;
Node(ll a=0,ll b=0)
{
v=a;dis=b;
}
friend bool operator <(Node a,Node b)
{
return a.dis >b.dis;
}
};
priority_queue<Node> v;
struct Edge
{
ll to,next,w;
}edge[N*7];
ll cnt,node[N],dis[N];
bool visit[N];
void add_edge(ll x,ll y,ll w)
{
edge[cnt].to =y;
edge[cnt].next =node[x];
edge[cnt].w =w;
node[x]=cnt++;
}
void dijkstra(int x)
{
mm(dis,inf);
mm(visit,false);
dis[x]=0;
Node t;
v.push(Node(x,0));
while(!v.empty())
{
t=v.top();
v.pop();
ll u=t.v;
if(visit[u]) continue;
visit[u]=1;
for(int i=node[u];i!=-1;i=edge[i].next)
{
ll to=edge[i].to,w=edge[i].w;
if(!visit[to]&&dis[to]>dis[u]+w)
{
dis[to]=dis[u]+w;
v.push(Node(to,dis[to]));
}
}
}
}
int main()
{
ll n,m,t,p;ll x,y,w;
cnt=0;mm(node,-1);
cin>>n>>m>>t>>p;
while(m--)
{
scfff(x,y,w);
add_edge(x,y,w);
add_edge(y,x,w);
}
while(t--)
{
scf(x);
add_edge(0,x,0);
}
map<ll,int> v;
while(p--)
{
scf(x);
v.insert(make_pair(x,1));
}
map<ll,int>::iterator it;
dijkstra(0);
ll ans=inf*100;
rep(i,1,n+1)
{
it=v.find(i);
if(it!=v.end())
ans=min(ans,dis[i]);
}
cout<<ans;
return 0;
}