比赛 |
NOIP2023模拟赛2 |
评测结果 |
EEEEEEEEEE |
题目名称 |
旅行者 |
最终得分 |
0 |
用户昵称 |
┭┮﹏┭┮ |
运行时间 |
1.916 s |
代码语言 |
C++ |
内存使用 |
44.36 MiB |
提交时间 |
2023-11-14 12:53:12 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
#define mp(x,y) make_pair(x,y)
const int N = 5e5+10,M = 1e6+10;
int n,m,t,k;
struct made{
int ver,nx;ll ed;
}e[M<<1];
int hd[N],tot,a[N];
int add(int x,int y,ll z){
tot++;
e[tot].ver = y,e[tot].nx = hd[x],e[tot].ed = z,hd[x] = tot;
}
ll d[N];
bool v[N];
void dij(int u){
memset(d,0x3f,sizeof(d));
memset(v,0,sizeof(v));
priority_queue<P,vector<P>,greater<P> >q;
q.push(mp(0,u));d[u] = 0;
while(!q.empty()){
int x = q.top().second;q.pop();
if(v[x])continue;
v[x] = 1;
for(int i = hd[x];i;i = e[i].nx){
int y = e[i].ver,z = e[i].ed;
if(d[x] + z < d[y]){
d[y] = d[x] + z;
q.push(mp(d[y],y));
}
}
}
}
void first(){
tot = 0;
memset(e,0,sizeof(e));
memset(hd,0,sizeof(hd));
memset(a,0,sizeof(a));
}
int main(){
freopen("WAW.in","r",stdin);
freopen("WAW.out","w",stdout);
scanf("%d",&t);
while(t--){
first();
scanf("%d%d%d",&n,&m,&k);
for(int i = 1;i <= m;i++){
int x,y;ll z;scanf("%d%d%lld",&x,&y,&z);
add(x,y,z);//单
}
for(int i = 1;i <= k;i++)scanf("%d",&a[i]);
ll ans = INT_MAX;
for(int i = 1;i <= k;i++){
dij(a[i]);
for(int j = 1;j <= k;j++){
if(i == j)continue;
ans = min(ans,d[a[j]]);
}
}
printf("%lld\n",ans);
}
return 0;
}