想了一个跑一次
d
i
j
dij
dij的做法
然后华丽丽的被叉掉了
这样还有
80
p
t
s
80pts
80pts
正解直接正反跑2次 d i j dij dij染色就可以了
#include<bits/stdc++.h>
using namespace std;
const int RLEN=1<<20|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ob==ib)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ob==ib)?EOF:*ib++;
}
inline int read(){
char ch=gc();
int res=0,f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
#define ll long long
#define re register
#define pii pair<int,ll>
#define fi first
#define se second
#define pb push_back
#define cs const
#define bg begin
#define poly vector<int>
inline void chemx(int &a,int b){a<b?a=b:0;}
inline void chemn(ll &a,ll b){a>b?a=b:0;}
cs int N=100005;
int n,m,k;
vector<pii> e[N],pe[N];
ll dis1[N],dis2[N];
int vis[N],tag[N],ist[N],pre1[N],pre2[N];
priority_queue<pii,vector<pii>,greater<pii> >q;
inline void dijkstra(ll *dis,int *pre){
memset(dis,127/4,sizeof(ll)*(n+1));
memset(vis,0,sizeof(vis));
for(int i=1;i<=k;i++)
dis[tag[i]]=0,q.push(pii(0,tag[i])),pre[tag[i]]=tag[i];
while(!q.empty()){
int u=q.top().se;q.pop();
if(vis[u])continue;
vis[u]=1;
for(pii &x:e[u]){
int v=x.fi;
if(dis[u]+x.se<dis[v]){
dis[v]=dis[u]+x.se;
pre[v]=pre[u];
q.push(pii(dis[v],v));
}
}
}
}
inline void solve(){
n=read(),m=read(),k=read();
for(int i=1;i<=m;i++){
int u=read(),v=read(),w=read();
pe[u].pb(pii(v,w)),e[v].pb(pii(u,w));
}
for(int i=1;i<=k;i++)tag[i]=read(),ist[tag[i]]=1;
dijkstra(dis1,pre1);
for(int i=1;i<=n;i++)e[i]=pe[i];
dijkstra(dis2,pre2);
ll res=1e18;
for(int u=1;u<=n;u++)
for(pii &x:e[u]){
if(pre1[x.fi]&&pre2[u]&&pre1[x.fi]!=pre2[u])chemn(res,dis1[x.fi]+dis2[u]+x.se);
}
cout<<res<<'\n';
for(int i=1;i<=n;i++)ist[i]=0,e[i].clear(),pe[i].clear(),pre1[i]=pre2[i]=0;
}
int main(){
#ifdef Stargazer
freopen("lx.cpp","r",stdin);
#endif
int T=read();
while(T--)solve();
}