#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; int N, M, K; int X[20]; int Y[20]; ll Z[20]; ll dist[20][20]; class UnionFind { public: vector _parent; vector _rank; vector _size; UnionFind(int n) { for (int i = 0; i < n; ++i) { _parent.push_back(i); _rank.push_back(0); _size.push_back(1); } } int find(int x) { if (_parent[x] == x) { return x; } else { return _parent[x] = find(_parent[x]); } } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (_rank[x] < _rank[y]) { _parent[x] = y; _size[y] += _size[x]; } else { _parent[y] = x; _size[x] += _size[y]; if (_rank[x] == _rank[y]) ++_rank[x]; } } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return _size[find(x)]; } }; struct Edge { int to; ll cost; int from; Edge(int to, ll cost, int from = -1) { this->to = to; this->cost = cost; this->from = from; } bool operator>(const Edge &n) const { return cost > n.cost; } }; vector E[20]; struct Node { int v; ll cost; Node(int v = -1, ll cost = -1) { this->v = v; this->cost = cost; } bool operator>(const Node &n) const { return cost > n.cost; } }; void setup_dist() { for (int v = 0; v < N; ++v) { priority_queue , greater> pque; pque.push(Node(v, 0LL)); vector visited(N, false); while (not pque.empty()) { Node node = pque.top(); pque.pop(); if (visited[node.v]) continue; visited[node.v] = true; dist[v][node.v] = node.cost; for (Edge &e : E[node.v]) { ll ncost = node.cost + e.cost; pque.push(Node(e.to, ncost)); } } } } int main() { cin >> N >> M >> K; int x, y; ll z; ll A[N]; for (int i = 0; i < N; ++i) { cin >> A[i]; } for (int i = 0; i < M; ++i) { cin >> x >> y >> z; --x; --y; E[y].push_back(Edge(x, z)); E[x].push_back(Edge(y, z)); } setup_dist(); ll ans = LLONG_MAX; for (int mask = 0; mask < (1 << N); ++mask) { if (__builtin_popcount(mask) != K) continue; vector V; for (int i = 0; i < N; ++i) { if (mask >> i & 1) { V.push_back(i); } } priority_queue , greater> pque; ll total_cost = 0; for (int i = 0; i < K; ++i) { int u = V[i]; total_cost += A[u]; for (int j = i + 1; j < K; ++j) { int v = V[j]; pque.push(Edge(v, dist[u][v], u)); } } UnionFind uf(N); while (not pque.empty()) { Edge e = pque.top(); pque.pop(); if (uf.same(e.from, e.to)) continue; uf.unite(e.from, e.to); total_cost += e.cost; } ans = min(ans, total_cost); } cout << ans << endl; return 0; }