func_code_string: #include <bits/stdc++.h>   using namespace std;   int dp, p[201000], tt[201000], pre[201000], l[201000], vis[201000];   int n, m, i, j, a[1010][1010], g[201000], now[201000], s, t, dis[201000],       z[201000], ans;   void link(int x, int y, int z) {     dp++;     pre[dp] = p[x];     p[x] = dp;     tt[dp] = y;     g[dp] = z;   }   int dfs(int x) {     int i;     i = p[x];     while (i) {       if (vis[tt[i]] == 0) {         vis[tt[i]] = 1;         if ((l[tt[i]] == 0) || (dfs(l[tt[i]]))) {           l[tt[i]] = x;           return 1;         }       }       i = pre[i];     }     return 0;   }   int bfs() {     int i, head, tail;     memcpy(now, p, sizeof(p));     memset(vis, 0, sizeof(vis));     head = 0;     tail = 1;     vis[s] = 1;     dis[s] = 0;     z[tail] = s;     do {       head++;       i = p[z[head]];       while (i) {         if ((vis[tt[i]] == 0) && (g[i] > 0)) {           vis[tt[i]] = 1;           dis[tt[i]] = dis[z[head]] + 1;           tail++;           z[tail] = tt[i];         }         i = pre[i];       }     } while (head != tail);     return vis[t];   }   int dfs(int u, int flow) {     int ans, tmp, i;     if (u == t) return flow;     i = now[u];     ans = 0;     while (i) {       if ((dis[u] + 1 == dis[tt[i]]) && (g[i] > 0)) {         tmp = dfs(tt[i], min(flow - ans, g[i]));         ans += tmp;         g[i] -= tmp;         if (i % 2 == 1)           g[i + 1] += tmp;         else           g[i - 1] += tmp;         if (flow == ans) return flow;       }       i = pre[i];       now[u] = i;     }     if (flow > ans) dis[u] = 1;     return ans;   }   int main() {     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a[i][0];       for (j = 1; j <= a[i][0]; j++) {         cin >> a[i][j];         link(n + i, a[i][j], 0);       }     }     for (i = n + 1; i <= 2 * n; i++) {       memset(vis, 0, sizeof(vis));       dfs(i);     }     dp = 0;     memset(p, 0, sizeof(p));     s = 0;     t = n + 1;     for (i = 1; i <= n; i++) {       cin >> m;       if (m > 0) {         link(s, i, m);         link(i, s, 0);       } else {         ans += m;         link(i, t, -m);         link(t, i, 0);       }     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= a[i][0]; j++)         if (l[a[i][j]] - n != i) {           link(l[a[i][j]] - n, i, 0x37373737);           link(i, l[a[i][j]] - n, 0);         }     }     while (bfs()) ans += dfs(s, 0x37373737);     cout << ans;   }   