#include<bits/stdc++.h>
#define int long long
using namespace std;
struct node{
int in;
int out;
int value;
};
bool cmp1(node x,node y){
return x.in<y.in;
}
bool cmp2(node x,node y){
return x.out<y.out;
}
int search(int a,int b[100001],int c){
int l=1,r=c;
int mid=(r+l)/2;
while(r-l>1){
if(b[mid]>a){
r=mid;
mid=(l+r)/2;
}
else if(b[mid]==a){
return 1;
}
else{
l=mid;
mid=(l+r)/2;
}
}
if(b[l]==a or b[r]==a) return 1;
else return 0;
}
int dis[400001];
node edge[700005];
int n,m,k;
signed main(){
//freopen("10.in","r",stdin);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
for(int h=0;h<t;h++){
for(int i=0;i<=700001;i++){
edge[i].in=0,edge[i].out=0,edge[i].value=0;
}
for(int i=0;i<=400000;i++){
dis[i]=9000000000000000000;
}
dis[0]=0;
cin>>n>>m>>k;
for(int i=1;i<=m;i++){
cin>>edge[i].in>>edge[i].out>>edge[i].value;
if(edge[i].in==edge[i].out){
edge[i].in+=300000;
}
}
int pnum[100001];
memset(pnum,0,sizeof(pnum));
for(int i=1;i<=k;i++){
cin>>pnum[i];
}
int start=1;
sort(pnum+1,pnum+k+1);
sort(edge+1,edge+m+1,cmp1);
for(int i=1;i<=k;i++){// O(1)
for(int j=start;j<=m;j++){// O(m+2*k)
if(edge[j].in>pnum[i]){
start=j;
break;
}
if(edge[j].in==pnum[i]){
if(search(edge[j].out,pnum,k)){//O(log2k)
edge[j].out+=100000;
}
}
}
}
start=1;
sort(edge+1,edge+m+1,cmp2);
for(int i=1;i<=k;i++){// O(1)
for(int j=start;j<=m;j++){// O(m+2*k)
if(edge[j].out>pnum[i]){
start=j;
break;
}
else if(edge[j].out==pnum[i]){
edge[j].out+=100000;
}
}
}
for(int i=1;i<=k;i++){
edge[m+i].in=0;
edge[m+i].out=pnum[i];
edge[m+i].value=0;
edge[m+k+i].in=pnum[i]+100000;
edge[m+k+i].out=n+100001;
edge[m+k+1].value=0;
}
/*for(int i=1;i<=m+2*k;i++){
cout<<edge[i].in<<" "<<edge[i].out<<'\n';
}*/
sort(edge+1,edge+m+1+2*k,cmp1);
for(int i=1;i<=m+2*k;i++){
for(int j=1+i;j<=m+2*k;j++){
//if(dis[edge[j].in]==9000000000000000000) continue;
if(edge[j].in>300000) continue;
dis[edge[j].out]=min(dis[edge[j].out],dis[edge[j].in]+edge[j].value);
}
}
cout<<dis[n+100001]<<'\n';
}
return 0;
}
理论上来说#1 #2 是没有问题的
测试后#1 错误
求逻辑指正 (前面的处理部分)