#include using namespace std; using ll = long long; template using pq = priority_queue, greater>; struct edge{ int to; ll cap, cost; int rev; }; struct MinCostFlow{ private: static const ll INF=9e18; vector dist, h; vector prevv, preve; vector> idx; void dijkstra(int s){ int from, c; pq> que; for (int i=0; i 0 && dist[e.to] > dist[from]+e.cost+h[from]-h[e.to]){ dist[e.to] = dist[from]+e.cost+h[from]-h[e.to]; prevv[e.to] = from; preve[e.to] = i; que.push({dist[e.to], e.to}); } } } } public: int N, M=0; vector> E; MinCostFlow(int n) : N(n) { E.resize(N); dist.resize(N); h.resize(N); prevv.resize(N); preve.resize(N); } void add_edge(int from, int to, ll cap, ll cost){ M++; idx.push_back({from, (int)E[from].size()}); E[from].push_back({to, cap, cost, (int)E[to].size()}); E[to].push_back({from, 0, -cost, (int)E[from].size()-1}); } ll solve(int s, int t, ll f){ ll res = 0, flow; fill(h.begin(), h.end(), 0); while(f){ dijkstra(s); if (dist[t] == INF) return -1; //no solution for (int i=0; i get_flow(int i){ assert (i < M); edge &e = E[idx[i].first][idx[i].second]; return {idx[i].first, e.to, E[e.to][e.rev].cap}; } }; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll K, N, M, u, v, d, s, t; cin >> K >> N >> M; MinCostFlow mcf(N+2); s = 0; t = N+1; vector A(N+1), B(N+1); for (int i=1; i<=K; i++){ cin >> u; A[u]++; } for (int i=1; i<=N; i++) cin >> B[i]; for (int i=1; i<=N; i++) mcf.add_edge(s, i, A[i], 0); for (int i=1; i<=N; i++) mcf.add_edge(i, t, B[i], 0); for (int i=0; i> u >> v >> d; mcf.add_edge(u, v, K, d); mcf.add_edge(v, u, K, d); } cout << mcf.solve(s, t, K) << endl; return 0; }