func_code_string: #include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);     int m, n;     cin >> m >> n;     vector<int> A(m), B(n);     for (int &i : A) cin >> i;     for (int &i : B) cin >> i;     vector<pair<int, pair<int, int>>> C;     for (int i = 0; i < m; ++i) {       int t;       cin >> t;       for (int j = 0; j < t; ++j) {         int a;         cin >> a;         --a;         C.emplace_back(make_pair(A[i] + B[a], make_pair(i, a)));       }     }     sort(C.rbegin(), C.rend());     long long res = 0;     vector<int> fa(n), fst(m, -1);     iota(fa.begin(), fa.end(), 0);     function<int(int)> ffa = [&](int x) {       if (fa[x] == x) return x;       return fa[x] = ffa(fa[x]);     };     auto merge = [&](int x, int y) {       x = ffa(x);       y = ffa(y);       if (x != y) {         fa[x] = y;       }     };     for (int i = 0; i < ((int)(C).size()); ++i) {       int v = C[i].first;       auto [idx, val] = C[i].second;       if (fst[idx] == -1) {         fst[idx] = val;         continue;       }       if (ffa(fst[idx]) == ffa(val)) {         res += v;       } else {         merge(fst[idx], val);       }     }     cout << res <<   n ;     return 0;   }   