#include #include using namespace atcoder; using namespace std; int main () { int N, S, T; cin >> N >> S >> T; std::vector E(S), R(T), ID(N, -1); for (auto& a : E) { cin >> a; a --; ID[a] = 0; } for (auto& a : R) { cin >> a; a --; ID[a] = 1; } using ll = long long; mf_graph mg(N + 2); ll C[66][66]; for (int i = 0; i < N; i ++) { for (int j = 0; j < N; j ++) { cin >> C[i][j]; } } for (int i = 0; i < N; i ++) { if (ID[i] != -1) { continue; } ll a = 0; for (int j : E) { a += C[i][j]; } mg.add_edge(N, i, a); a = 0; for (int j : R) { a += C[i][j]; } mg.add_edge(i, N + 1, a); for (int j = 0; j < N; j ++) { if (i != j) { mg.add_edge(i, j, C[i][j]); } } } ll ans = 0; for (int i = 0; i < N; i ++) { for (int j = i; j < N; j ++) { ans += C[i][j]; } } cout << ans - mg.flow(N, N + 1) << endl; }