func_code_string: #include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   int n, c[1011], vao[1011], save[1011];   vector<int> ke[1011];   bool mark[1011];   int get(int start) {     for (int i = (1), _b = (n); i <= _b; i++) vao[i] = save[i];     int done = 0, res = 0;     memset(mark, false, sizeof mark);     while (done < n) {       int inc = 0;       for (int i = (1), _b = (n); i <= _b; i++)         if (!mark[i] && vao[i] == 0 && c[i] == start) {           mark[i] = true;           ++done;           ++inc;           for (int x = 0, _a = (ke[i].size()); x < _a; x++) {             int u = ke[i][x];             vao[u]--;           }         }       if (done == n) break;       if (!inc) {         if (start == 3)           start = 1;         else           ++start;         ++res;       }     }     return res;   }   int main() {     scanf( %d , &n);     for (int i = (1), _b = (n); i <= _b; i++) scanf( %d , &c[i]);     for (int i = (1), _b = (n); i <= _b; i++) {       scanf( %d , &save[i]);       for (int x = (1), _b = (save[i]); x <= _b; x++) {         int u;         scanf( %d , &u);         ke[u].push_back(i);       }     }     int res = n * 4;     for (int start = (1), _b = (3); start <= _b; start++) {       res = min(res, get(start));     }     cout << res + n << endl;     return 0;   }   