#include #include #include #include using namespace std; using ll = long long; const ll INF = LLONG_MAX / 4; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int N, S, T; cin >> N >> S >> T; const int src = N, dst = N + 1; atcoder::mf_graph g(N + 2); while(S--) { int A; cin >> A; A--; g.add_edge(src, A, INF); } while(T--) { int B; cin >> B; B--; g.add_edge(B, dst, INF); } ll ans = 0; for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) { ll C; cin >> C; if(i < j) { ans += C; g.change_edge(g.add_edge(i, j, 0), C * 2, C); } } cout << ans - g.flow(src, dst) << endl; }