#include #include int main() { using namespace std; unsigned N, M; cin >> N >> M; atcoder::mf_graph g(1 + N + M + 1); for (unsigned i = 0; i < N; ++i) { unsigned A; cin >> A; g.add_edge(0, 1 + i, A); } unsigned long inf{}; for (unsigned i = 0; i < M; ++i) { unsigned B; cin >> B; inf += B; g.add_edge(1 + N + i, 1 + N + M, B); } for (unsigned i = 0; i < M; ++i) { unsigned C; cin >> C; for (unsigned j = 0; j < C; ++j) { unsigned D; cin >> D; g.add_edge(D, 1 + N + i, inf); } } cout << inf - g.flow(0, 1 + N + M) << endl; return 0; }