Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////


struct edge{ ll to,cost; };
vector<edge> G[500010];
ll d[500010][500010];

void dijkstra(ll s){
    fill(d[s],d[s]+500010,inf);
    d[s][s]=0;
    priority_queue<l_l,vector<l_l>,greater<l_l>> que;
    que.push(l_l(0,s));
    while(!que.empty()){
        l_l p=que.top();que.pop();
        ll v=p.second;
        if(d[s][v]<p.first)continue;
        if(G[v].size()>0){
            rep(i,0,G[v].size()-1){
                edge e=G[v][i];
                if(d[s][e.to]>d[s][v]+e.cost){
                    d[s][e.to]=d[s][v]+e.cost;
                    que.push(l_l(d[s][e.to],e.to));
                }
            }
        }
    }
}

vector<vector<ll>> K;

vector<ll> Desk;
bool Bol[100000];
ll Counter;
void Rep(ll x){
    if(Desk.size()==x){
        K.pb(Desk);
        Counter++;
        return ;
    }
    rep(i,0,x-1){
        if(!Bol[i]){
            Desk.pb(i);Bol[i]=true;
            Rep(x);
            Desk.pop_back();Bol[i]=false;
        }
    }
}


int main(){
    ll n,m,R;cin>>n>>m>>R;
    ll r[R];
    rep(i,0,R-1)cin>>r[i];
    ll a,b,c;
    edge e;
    rep(i,0,m-1){
        cin>>a>>b>>c;
        e.to=b;
        e.cost=c;
        G[a].pb(e);
        e.to=a;
        G[b].pb(e);
    }
    rep(i,1,n){
        dijkstra(i);
    }
    Rep(R);
    ll sum=0;
    ll ans=inf;
    vector<ll> vv;
    rep(i,0,K.size()-1){
        sum=0;
        vv=K[i];
        rep(j,0,R-2){
            sum+=d[r[vv[j]]][r[vv[j+1]]];
        }
        ans=min(sum,ans);
    }
    cout<<ans<<endl;
    return 0;
}


Compiler output:
/tmp/ccfua4RD.o: in function `Rep(long long)':
a.cc:(.text+0x48c): relocation truncated to fit: R_X86_64_PC32 against symbol `Desk' defined in .bss section in /tmp/ccfua4RD.o
a.cc:(.text+0x4ac): relocation truncated to fit: R_X86_64_PC32 against symbol `Desk' defined in .bss section in /tmp/ccfua4RD.o
a.cc:(.text+0x4b6): relocation truncated to fit: R_X86_64_PC32 against symbol `K' defined in .bss section in /tmp/ccfua4RD.o
a.cc:(.text+0x4c5): relocation truncated to fit: R_X86_64_PC32 against symbol `Counter' defined in .bss section in /tmp/ccfua4RD.o
a.cc:(.text+0x4d0): relocation truncated to fit: R_X86_64_PC32 against symbol `Counter' defined in .bss section in /tmp/ccfua4RD.o
a.cc:(.text+0x4ea): relocation truncated to fit: R_X86_64_PC32 against symbol `Bol' defined in .bss section in /tmp/ccfua4RD.o
a.cc:(.text+0x503): relocation truncated to fit: R_X86_64_PC32 against symbol `Desk' defined in .bss section in /tmp/ccfua4RD.o
a.cc:(.text+0x516): relocation truncated to fit: R_X86_64_PC32 against symbol `Bol' defined in .bss section in /tmp/ccfua4RD.o
a.cc:(.text+0x52d): relocation truncated to fit: R_X86_64_PC32 against symbol `Desk' defined in .bss section in /tmp/ccfua4RD.o
a.cc:(.text+0x540): relocation truncated to fit: R_X86_64_PC32 against symbol `Bol' defined in .bss section in /tmp/ccfua4RD.o
/tmp/ccfua4RD.o: in function `main':
a.cc:(.text+0x780): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status