两个迪杰斯特拉,卡在优先队列符号重载
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 1e6+10;
const int mod=998244353;
int tot=0,V,E,S,K,C;
int head[1005],vis[1005];
ll dis[1005];
struct Edge
{
int v,nex;
ll val;
Edge(){}
Edge(int v,ll val):v(v),val(val){}
bool operator < (const Edge & x)const
{
return val>x.val;
}
}l[maxn*2];
void init()
{
tot=0;
memset(head,-1,sizeof head);
}
void addedge(int u,int v,ll val)
{
l[tot].val=val;
l[tot].v=v;
l[tot].nex=head[u];
head[u]=tot++;
}
ll dij(int st)
{
priority_queue<Edge>q;
memset(vis,0,sizeof vis);
memset(dis,LINF,sizeof dis);
q.push(Edge(st,0));
dis[st]=0;
while(!q.empty())
{
Edge now=q.top();
q.pop();
int u=now.v;
if(vis[u]==1)continue;
vis[u]=1;
for(int i=head[u];i!=-1;i=l[i].nex){
if(dis[u]+l[i].val<dis[ l[i].v ]){
dis[ l[i].v ]=dis[u]+l[i].val;
q.push(Edge(l[i].v,dis[ l[i].v ]));
}
}
}
int maxx=0;
for(int i=1;i<=V;i++){
if(maxx<dis[i])maxx=dis[i];
}
return maxx;
}
int main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
int t;
scanf("%d",&t);
while(t--){
init();
scanf("%d%d%d%d%d",&V,&E,&S,&K,&C);
for(int i=1;i<=K;i++){
int x;
scanf("%d",&x);
addedge(V+1,x,0);
}
for(int i=1;i<=E;i++){
int u,v;
ll val;
scanf("%d%d%lld",&u,&v,&val);
addedge(u,v,val);
addedge(v,u,val);
}
ll hero=dij(S),team=dij(V+1);
if(hero>team*(ll)C){
printf("%lld\n",team);
}
else{
printf("%lld\n",hero);
}
}
return 0;
}