#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int, int> PII;
const int N = 50010, M = 200010, inf = 0x3f3f3f3f;
int h[N], ne[M], e[M], w[M], idx;
int dist[6][N], n, m, sources[6];
bool st[N];
void add(int a, int b, int c)
{
e[idx] = b, ne[idx] = h[a], w[idx] = c, h[a] = idx ++ ;
}
void dijkstra(int u, int d[])
{
priority_queue<PII, vector<PII>, greater<PII>> heap;
d[u] = 0;
heap.push({0, u});
while (heap.size())
{
PII t = heap.top();
heap.pop();
int weight = t.first, ix = t.second;
if (st[ix]) continue;
st[ix] = true;
for (int i = h[ix]; i != -1; i = ne[i])
{
int j = e[i];
if (d[j] > w[i] + weight)
{
d[j] = w[i] + weight;
heap.push({d[j], j});
}
}
}
memset(st, false, sizeof st);
}
int dfs(int u, int from, int dis)
{
if (u == 6) return dis;
int ans = inf;
for (int i = 1; i <= 5; i ++)
if (!st[i])
{
int x = sources[i];
st[i] = true;
ans = min(ans, dfs(u + 1, i, dis + dist[from][x]));
st[i] = false;
}
return ans;
}
int main()
{
scanf("%d%d", &n, &m);
sources[0] = 1;
for (int i = 1; i <= 5; i ++) scanf("%d", &sources[i]);
memset(dist, inf, sizeof dist);
memset(h, -1, sizeof h);
while (m -- )
{
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
add(a, b, c), add(b, a, c);
}
for (int i = 0; i < 6; i ++) dijkstra(sources[i], dist[i]);
printf("%d\n", dfs(1, 0, 0));
return 0;
}
还是你强