#define CP_BUNDLED_SOURCE #ifndef CP_BUNDLE_HEADER_3840A09F237A779E #define CP_BUNDLE_HEADER_3840A09F237A779E #ifdef TEMPLATE #else #define TEMPLATE # pragma GCC optimize("O3") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using uint=unsigned; using ll=long long; using ull=unsigned long long; using ld=long double; using pii=pair; using pll=pair; using i128=__int128; using u128=unsigned __int128; templateusing vc=vector; templateusing vvc=vc>; templateusing vvvc=vvc>; templateusing smpq=priority_queue,greater>; templateusing bipq=priority_queue; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define REP(i,j,n) for(ll i=(j);i<(ll)(n);i++) #define DREP(i,n,m) for(ll i=(n);i>=(m);i--) #define drep(i,n) for(ll i=((n)-1);i>=0;i--) #define rall(x) x.rbegin(),x.rend() #define mp(...) make_pair(__VA_ARGS__) #define pb push_back #define fi first #define se second #define is insert #define bg begin() #define ed end() #define all(x) x.begin(),x.end() void scan(int&a) { cin >> a; } void scan(ll&a) { cin >> a; } void scan(string&a) { cin >> a; } void scan(char&a) { cin >> a; } void scan(uint&a) { cin >> a; } void scan(ull&a) { cin >> a; } void scan(bool&a) { cin >> a; } void scan(ld&a){ cin>> a;} template void scan(vector&a) { for(auto&x:a) scan(x); } void read() {} template void read(Head&head, Tail&... tail) { scan(head); read(tail...); } #define INT(...) int __VA_ARGS__; read(__VA_ARGS__); #define LL(...) ll __VA_ARGS__; read(__VA_ARGS__); #define ULL(...) ull __VA_ARGS__; read(__VA_ARGS__); #define STR(...) string __VA_ARGS__; read(__VA_ARGS__); #define VC(type, name, ...) vector name(__VA_ARGS__); read(name); #define VVC(type, name, size, ...) vector> name(size, vector(__VA_ARGS__)); read(name); templatevoid print(T a) { cout << a; } template void print(vectora) { for(int i=0;i<(int)a.size();i++){if(i)cout<<" ";print(a[i]);}} void PRT() { cout < void PRT(T a) { print(a); cout < void PRT(Head head, Tail ... tail) { print(head); cout << " "; PRT(tail...); return; } template bool chmin(T &x, F y){ if(x>y){ x=y; return true; } return false; } template bool chmax(T &x, F y){ if(x T floor(T a,T b){ return a/b-(a%b&&((a<0)!=(b<0))); } template T ceil(T a,T b){ return a/b+(a%b&&((a<0)==(b<0))); } template T bmod(T x,T y){ return x-y*floor(x,y); } template pairdivmod(T x,T y){ T q=floor(x,y); return{q,x-q*y}; } void YesNo(bool b){ cout<<(b?"Yes":"No")<stovi(const string&s,const string&S){ vcv(s.size()); rep(i,s.size()){ auto t=S.find(s[i]); assert(t!=string::npos); v[i]=t; } return v; } template T isqrt(T x){ T F=sqrtl(x); while((F+1)*(F+1)<=x)F++; while(F*F>x)F--; return F; } template T tri(T x){return x*(x-1)/2;} //[l,r) templateT tri(T l,T r){return (r-l)*(l+r-1)/2;} //n を先頭に持ってくる template vcrot(vcv,int n){ rotate(v.begin(),v.begin()+n,v.end()); return v; } template vciota(int n){ vcv(n);rep(i,n)v[i]=i; return v; } template vcargsort(const vc&a){ auto idx=iota(a.size()); sort(all(idx),[&](int i,int j){ return (minfirst?make_pair(a[i],i)make_pair(a[j],j)); }); return idx; } template vvctrans(const vvc&a){ assert(a.size()&&a[0].size()); rep(i,a.size())assert(a[i].size()==a[0].size()); vvcb(a[0].size(),vc(a.size())); rep(i,a.size())rep(j,a[0].size())b[j][i]=a[i][j]; return b; } vctrans(const vc&a){ assert(a.size()&&a[0].size()); rep(i,a.size())assert(a[i].size()==a[0].size()); vcb(a[0].size(),string(a.size(),0)); rep(i,a.size())rep(j,a[0].size())b[j][i]=a[i][j]; return b; } template int popcount(T n){ return __builtin_popcountll(n); } template L sum(const vc&a){ return accumulate(all(a),L(0)); } template struct subset_view{ T s; struct iterator{ T s,x; bool done; T operator*()const{return x;} iterator&operator++(){ if(x==0)done=true; else x=(x-1)&s; return*this; } bool operator!=(const iterator&r)const{return done!=r.done;} }; iterator begin()const{return{s,s,false};} iterator end()const{return{s,0,true};} }; template subset_viewsubset(T s){ return{s}; } template T max(vc&a){ return *max_element(all(a)); } template T min(vc&a){ return *min_element(all(a)); } template vc presum(vc &a){ vc ret(a.size()+1); rep(i,a.size())ret[i+1]=ret[i]+a[i]; return ret; } template vc &operator+=(vc &a,F b){ for (auto&v:a)v += b; return a; } template vc &operator-=(vc&a,F b){ for (auto&v:a)v-=b; return a; } template vc &operator*=(vc&a,F b){ for (auto&v:a)v*=b; return a; } template constexpr T pow(T a,T b){ T res=1; while(b){ if(b&1)res*=a; a*=a; b/=2; } return res; } constexpr ll ten(ll a){ return pow(10,a); } templateconstexpr T inf=numeric_limits::max()/2-1; template int tbit(T x){ using U=make_unsigned_t; U y=(U)x; return y?(int)bit_width(y)-1:-1; } template int lbit(T x){ using U=make_unsigned_t; U y=(U)x; return y?(int)countr_zero(y):-1; } template int tbit(T x,int p){ using U=make_unsigned_t; constexpr int W=numeric_limits::digits; U y=(U)x; if(p<0)return -1; if(p>=W-1)return tbit(y); return tbit(y&((U(1)<<(p+1))-1)); } template int lbit(T x,int p){ using U=make_unsigned_t; constexpr int W=numeric_limits::digits; U y=(U)x; if(p<0)return lbit(y); if(p>=W)return -1; return lbit(y&(~U(0)<>(istream&is,i128&x){ string s;is>>s; x=0; int i=0,neg=0; if(s[0]=='-')neg=1,i=1; for(;i<(int)s.size();i++)x=x*10+s[i]-'0'; if(neg)x=-x; return is; } ostream& operator<<(ostream&os,i128 x){ if(x==0)return os<<0; if(x<0)os<<"-"; u128 y=x<0?-(u128)x:(u128)x; string s; while(y)s.pb('0'+y%10),y/=10; reverse(all(s)); return os<sync_with_stdio(0); #ifdef LOCAL cout< #endif #endif #endif #ifndef CP_BUNDLE_HEADER_A415336C78CC3AB3 #define CP_BUNDLE_HEADER_A415336C78CC3AB3 struct unweighted{ unweighted()=default; unweighted(int){} operator int()const{return 1;} }; template struct edge{ int from,to,id; [[no_unique_address]]T cost; #ifdef LOCAL friend ostream&operator<<(ostream&os,const edge&e){ return os<<"{from:"< struct static_graph{ constexpr static bool directed(){return is_directed;} using edge=::edge; using cost_t=T; private: int n; mutable bool built=false,inv_built=false; vcedges; mutable vcstart,inv_start; mutable vccsr,inv_csr; public: static_graph(int n):n(n),start(n+1),inv_start(n+1){assert(n>=0);} static_graph(int n,int m):static_graph(n){assert(m>=0);edges.reserve(m);} void resize(int size){ assert(n<=size&&!built); assert(!inv_built); n=size; start.resize(n+1); inv_start.resize(n+1); } void add_edge(const edge&e){ assert(!built&&!inv_built); assert(0<=e.from&&e.from void input(int m){ assert(m>=0); rep(i,m){ INT(a,b); a-=substract;b-=substract; add_edge(a,b); } build(); } void build()const{ if(built)return; built=true; start.assign(n+1,0); for(auto&e:edges){ ++start[e.from]; if constexpr(!is_directed)++start[e.to]; } rep(i,n)start[i+1]+=start[i]; csr.resize(start[n]); for(auto it=edges.rbegin();it!=edges.rend();++it){ auto&e=*it; csr[--start[e.from]]=e; if constexpr(!is_directed)csr[--start[e.to]]={e.to,e.from,e.id,e.cost}; } } void buildinv()const{ if(inv_built)return; inv_start.assign(n+1,0); for(auto&e:edges){ ++inv_start[e.to]; if constexpr(!is_directed)++inv_start[e.from]; } rep(i,n)inv_start[i+1]+=inv_start[i]; inv_csr.resize(inv_start[n]); for(auto it=edges.rbegin();it!=edges.rend();++it){ auto&e=*it; inv_csr[--inv_start[e.to]]={e.to,e.from,e.id,e.cost}; if constexpr(!is_directed)inv_csr[--inv_start[e.from]]={e.from,e.to,e.id,e.cost}; } inv_built=true; } auto operator[](int u){ build(); assert(0<=u&&u(csr.data()+start[u],start[u+1]-start[u]); } auto operator[](int u)const{ build(); assert(0<=u&&u(csr.data()+start[u],start[u+1]-start[u]); } auto inv(int u){ buildinv(); assert(0<=u&&u(inv_csr.data()+inv_start[u],inv_start[u+1]-inv_start[u]); } auto inv(int u)const{ buildinv(); assert(0<=u&&u(inv_csr.data()+inv_start[u],inv_start[u+1]-inv_start[u]); } const vc&all_edges()const{return edges;} int edge_size()const{return edges.size();} edge get_edge(int id)const{ assert(0<=id&&id vvcadj()const{ vvcres(n,vc(n)); for(auto&e:edges){ res[e.from][e.to]=e.cost; if constexpr(!is_directed)res[e.to][e.from]=e.cost; } return res; } void clear(){ built=false; inv_built=false; edges.clear(); csr.clear(); inv_csr.clear(); start.assign(n+1,0); inv_start.assign(n+1,0); } template void sort(int i,F f){ build(); assert(0<=i&&i vcslow_dijkstra(const Graph&g,vcstarts){ int n=g.size(); vcmd(n,inf); for(auto&x:starts)md[x]=0; vcdone(n); rep(i,n){ pairtarget{inf,-1}; rep(j,n){ if(!done[j]){ chmin(target,pair{md[j],j}); } } if(target.se==-1)continue; done[target.se]=1; for(auto&e:g[target.se]){ chmin(md[e.to],md[target.se]+e.cost); } } return md; } void solve(){ LL(n,m,k); VC(ll,a,n); static_graph<0,ll>g(n); rep(i,m){ LL(x,y,z);--x,--y;g.add_edge(x,y,z); } vcdp(1<);dp[0]=0; rep(i,1<start;rep(j,n)if(i>>j&1)start.pb(j); auto res=slow_dijkstra(g,start); rep(add,n){ if(i>>add&1)continue; chmin(dp[i+(1<;rep(i,1<> t; while(t--)solve(); }