比赛 |
2025.6.2 |
评测结果 |
AAAATTTTATAT |
题目名称 |
旅行者 |
最终得分 |
50 |
用户昵称 |
彭欣越 |
运行时间 |
31.486 s |
代码语言 |
C++ |
内存使用 |
8.84 MiB |
提交时间 |
2025-06-02 12:02:41 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int M=500010;
typedef long long ll;
ll t,n,m,k,a[M],b[M],c[M],mk[M],tot,cnt,maxx,cnt1,cnt2,dis[M],res=1e9+10;
ll head[M];
inline ll read(){
ll x = 0,f = 1; char c = getchar();
while (c != EOF && !isdigit(c)) {if (c == '-') f = -1;c = getchar();}
while (isdigit(c)) {x = x * 10 + c - '0';c = getchar();}
return x * f;
}
struct node {
ll v,w,nxt;
}e[M];
void add (ll u,ll v,ll w) {
e[++tot].v=v;
e[tot].w=w;
e[tot].nxt=head[u];
head[u]=tot;
}
struct edge {
ll t,dis;
bool operator <(const edge &o) const{
return o.dis<dis;
}
};
void dij (int s) {
priority_queue<edge>q;
dis[s]=0;
q.push((edge){s,0});
while(!q.empty()) {
ll t=q.top().dis;
ll u=q.top().t;
q.pop();
if (mk[u]) continue;
mk[u]=1;
//cout << u <<' '<< t <<endl;
for (int i=head[u];i;i=e[i].nxt) {
long long v=e[i].v,w=e[i].w;
//cout << w <<endl;
if (dis[v]>dis[u]+w) {
dis[v]=dis[u]+w;
//cout << v <<' '<< u <<' '<< dis[v] <<endl;
q.push((edge){v,dis[v]});
}
}
}
}
int main () {
freopen("WAW.in","r",stdin);
freopen("WAW.out","w",stdout);
//cout << (10&(1<<3)) <<endl;
t=read();
//memset(dis,0x3f,sizeof(dis));
while (t--) {
cnt=0,res=1e9+10;
n=read(),m=read(),k=read();
tot=0;
for (int i=1;i<=n;i++) head[i]=0;
for (int i=1;i<=m;i++) {
long long a,b,c;
a=read(),b=read(),c=read();
add(a,b,c);
}
for (int i=1;i<=k;i++) {
a[i]=read();
}
//for (long long j=1;j<=cnt1;j++) cout << b[j] <<' ';
//cout <<endl;
//for (long long j=1;j<=cnt2;j++) cout << c[j] <<' ';
//cout <<endl;
//cout << cnt1 <<' '<< cnt2 <<endl;
//if (cnt1==0||cnt2==0) continue;
for (int i=1;i<=k;i++) {
for (int j=1;j<=n;j++) {
dis[j]=1e9+10;
mk[j]=0;
}
dij(a[i]);
for (int j=1;j<=k;j++) {
if (i==j) continue;
//cout << dis[c[k]] <<' ';
res=min(res,dis[a[j]]);
}
//cout <<endl;
}
printf("%d\n",res);
}
return 0;
}