func_code_string: #include <bits/stdc++.h>   using namespace std;   using namespace std;   const int mod = (int)1e9 + 7;   const long long INF = 10000005;   const int inf = 1 << 30;   char buf[1000];   const int N = 210;   vector<int> dep[N];   vector<int> computer[3];   bool completed[N];   int n;   int check(int start) {     int tot = 0, done = 0;     memset(completed, false, sizeof(completed));     while (done < n) {       bool found = true;       while (found) {         found = false;         for (vector<int>::iterator i = computer[start].begin();              i != computer[start].end(); ++i) {           if (!completed[*i]) {             bool cando = true;             for (vector<int>::iterator j = dep[*i].begin(); j != dep[*i].end();                  ++j) {               if (!completed[*j]) {                 cando = false;                 break;               }             }             if (cando) {               done++;               completed[*i] = true;               found = true;             }           }         }       }       if (done < n) {         tot++;         start = (start + 1) % 3;       }     }     return tot;   }   int main() {     cin >> n;     int tmp;     for (int i = 0; i < n; ++i) {       scanf( %d , &tmp);       computer[tmp - 1].push_back(i);     }     for (int i = 0; i < n; ++i) {       int d;       scanf( %d , &d);       for (int j = 0; j < d; ++j) {         scanf( %d , &tmp);         dep[i].push_back(tmp - 1);       }     }     cout << n + min(check(0), min(check(1), check(2))) << endl;   }   