#include using namespace std; #include using namespace atcoder; const long long INF = 1e18; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n,k,m; cin >> k >> n >> m; vector A(k); vector B(n); for (auto &a: A) cin >> a; for (auto &b: B) cin >> b; vector>> e(n); for (int i = 0; i < m ; i++){ int u,v; long long d; cin >> u >> v >> d; u--;v--; e[u].emplace_back(v,d); e[v].emplace_back(u,d); } int s = n+n, t = s+1; mcf_graph g(t+1); vector count(n); for (int i = 0; i < k; i++){ count[A[i]-1]++; } for (int i = 0; i < n; i++){ if (B[i]){ int mi = min(B[i],count[i]); B[i] -= mi; count[i] -= mi; } } for (int i = 0; i < n; i++){ if (count[i]==0) continue; vector dist(n,INF); dist[i] = 0; priority_queue,vector>,greater>> h; h.push(pair(0,i)); while (!h.empty()) { auto [d,now] = h.top(); h.pop(); if (dist[now] != d) continue; for (auto [nex,nd]: e[now]){ if (dist[nex] > d+nd){ dist[nex] = d+nd; h.push(pair(d+nd,nex)); } } } for (int j = 0; j < n; j++){ if (B[j] == 0) continue; g.add_edge(i,n+j,count[i],dist[j]); } } int flow = 0; for (int i = 0; i < n; i++){ if (B[i]){ g.add_edge(n+i,t,B[i],0); } if (count[i]){ g.add_edge(s,i,count[i],0); flow += count[i]; } } auto result = g.flow(s,t,flow); cout << result.second << endl; return 0; }