Language: C++

// Implementation practice (Have seen the editorial)
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef set<int> si;
typedef priority_queue<int> pqi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define loop(i, a) for (int i = 0; i < (a); i++)
#define loop1(i, a) for (int i = 1; i <= (a); i++)
#define loopr(i, a, b) for (int i = (a); i <= (b); i++)
#define dloop(i, a) for (int i = (a) - 1; i >= 0; i--)
#define dloopr(i, b, a) for (int i = (b); i >= (a); i--)
#define show(a) cout << a << "\n"
#define showloop(a, len) for (int i = 0; i < len; i++) cout << a[i] << "\n"
#define itloop(a, len) for (int i = 0; i < len; i++) cout << a[i] << "\n"
#define debug(a) cout << #a << ": " << (a) << "\n"
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) ((int)x.size())
#define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))
const int MOD = 1000000007;
const double PI = acos(-1);

const int N = 201, M = 400, R = 9;
int n, m, r;
int city[R];
ll path[N][N];

struct node {
	int at;
  	ll cost;
	node(int _at, ll _cost) {
		at = _at;
		cost = _cost;
	}
};
bool operator<(node A, node B) {
	return A.cost > B.cost;
};
struct edge {
	int v, cost;
	edge(int _v, int _cost) {
		v = _v;
		cost = _cost;
	}
};

vector<edge> road[N];
priority_queue<node> pq;
ll dist[N];
bool visited[N];

void dijkstra(int root) {
	loop1(i, N - 1) dist[i] = (ll)MOD;
	dist[root] = (ll)0;
	pq.push(node(root, 0));

	while(!pq.empty()) {
		node nearest = pq.top();
		pq.pop();

		if (nearest.cost != dist[nearest.at]) continue;
		for (edge e: road[nearest.at]) {
			if (dist[e.v] > nearest.cost + e.cost) {
				dist[e.v] = (ll)nearest.cost + e.cost;
				pq.push(node(e.v, dist[e.v]));
			}
		}
	}

	loop1(i, r) {
		if (city[i] == root) continue;
		path[root][city[i]] = (ll)dist[city[i]];
	}
}

int main() {
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	ios::sync_with_stdio(false);cin.tie(NULL);

	cin >> n >> m >> r;
	loop1(i, r) cin >> city[i];
	loop1(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		road[a].pb(edge(b, c));
		road[b].pb(edge(a, c));
	}

	ll ans = MOD << 5;
	loop1(i, r) dijkstra(city[i]);
	int cities[r];
	loop(i, r) cities[i] = city[i + 1];
  	sort(cities.begin(), cities.end());
	do {
		ll curr = (ll)0;
		loop1(i, r - 1) curr += (ll)path[cities[i - 1]][cities[i]];
		ans = min(curr, ans);
	} while (next_permutation(cities, cities + r));
	show(ans);

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:102:22: warning: result of '(1000000007 << 5)' requires 36 bits to represent, but 'int' only has 32 bits [-Wshift-overflow=]
  102 |         ll ans = MOD << 5;
      |                  ~~~~^~~~
a.cc:106:21: error: request for member 'begin' in 'cities', which is of non-class type 'int [r]'
  106 |         sort(cities.begin(), cities.end());
      |                     ^~~~~
a.cc:106:37: error: request for member 'end' in 'cities', which is of non-class type 'int [r]'
  106 |         sort(cities.begin(), cities.end());
      |                                     ^~~