rt,70PTS TLE on 5,6,7
是两个log的写法。
#include<bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define lll __int128
#define ull unsigned long long
#define ld long double
#define gc getchar();
#define pc(x) putchar(x)
#define adde(x,y) emplace_back(make_pair(x,y))
namespace constant_warrior{
template<typename T> inline void fr(T& num){
num=0;short sign=1;char ch=std::getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')sign=-1;
ch=std::getchar();
}
while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
num=num*sign;
}
template<typename T>inline void fw(T x){
if(x<0)std::putchar('-'),x=-x;
if(x>9)fw(x/10);
std::putchar(x%10+'0');
}
template<typename T>inline const T& maxf(const T& a,const T& b){
if(a>b)return a;
return b;
}
template<typename T>inline const T& minf(const T& a,const T& b){
if(a>b)return b;
return a;
}
template<typename T>inline void swapf(T& a,T& b){
a^=b^=a^=b;
}
}
using namespace constant_warrior;
const int N=1<<17;
int n,m,k,s,t;
int num[N];
vector<pair<int,int> > g[N];
ll dis[N];
bitset<N> mk;
inline void dijkstra(int s){
__gnu_pbds::priority_queue<pair<ll,int>,greater<pair<ll,int> >,thin_heap_tag> pq;
pq.push(make_pair(0,s));
for(int i=1;i<=n+16;i++)dis[i]=0x3f3f3f3f3f3f3f;
dis[s]=0;
mk.reset();
while(pq.size()){
int x=pq.top().second;pq.pop();
if(mk[x])continue;
mk[x]=1;
for(auto i:g[x]){
int y=i.first,z=i.second;
if(dis[y]>dis[x]+z){
dis[y]=dis[x]+z;
pq.push(make_pair(dis[y],y));
}
}
}
}
void solve(){
fr(n),fr(m),fr(k);
for(int i=1;i<=n+16;i++){
g[i].clear();
}
while(m-->0){
int x,y,z;fr(x),fr(y),fr(z);
g[x].adde(y,z);
}
for(int i=1;i<=k;i++){
fr(num[i]);
}
ll res=0x3f3f3f3f3f3f3f3f;
for(int i=0;i<=16;i++){
g[n+1].clear();g[n+2].clear();
g[n+3].clear();g[n+4].clear();
for(int j=1;j<=k;j++){
if(i)g[num[j]].pop_back();
if(num[j]&(1<<i)){
g[n+1].emplace_back(make_pair(num[j],0));
g[num[j]].emplace_back(make_pair(n+3,0));
}
else{
g[n+2].emplace_back(make_pair(num[j],0));
g[num[j]].emplace_back(make_pair(4+n,0));
}
}
dijkstra(n+1);
res=minf(res,dis[4+n]);
dijkstra(n+2);
res=minf(res,dis[3+n]);
}
fw(res),pc('\n');
}
_Atomic_word main(){
// ios::sync_with_stdio(0);
// cin.tie(0);cout.tie(0);
int Count=1;fr(Count);
while(Count-->0)solve();
}
/*
多测不清空,OI见祖宗。
multitesting without clearing,oier meets the LCA.
十年OI一场空,不开LL见祖宗。
Ten years of OI just AFO,no #define int long long sees the LCA.
似是神犇成才处,实为蒟蒻黄泉路。
It is likely to be the Au medal for the big old,but in fact it is the Si medal for me.
黄题有恨无正解,码力不若小学生。
A yellow problem I can't AC,codeforces is not as NB as EUlar Shai.
今生无奈入OI,来世不做信竞人。
This life I am a Siliy Being in oi,next life I won't f**k the sh*t of infomatics.
*/