func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 205;   const int mod = 1e9 + 7;   int n, m, t, q;   vector<int> G[N];   map<int, int> M;   set<int> S;   int a[N], in[N], iinn[N], vis[N];   long long sum;   void topsort(int id) {     int cnt = 0;     while (1) {       for (int i = (1); i <= (n); i++) {         if (iinn[i] == 0 && vis[i] == 0 && a[i] == id) {           cnt++;           vis[i] = 1;           sum++;           int len = G[i].size();           for (int j = (0); j <= (len - 1); j++) {             iinn[G[i][j]]--;           }           i = 0;         }       }       if (cnt == n) break;       id = (id % 3) + 1;       sum++;     }   }   int main() {     scanf( %d , &n);     for (int i = (1); i <= (n); i++) scanf( %d , &a[i]);     for (int i = (1); i <= (n); i++) {       int len, num;       scanf( %d , &len);       for (int j = (1); j <= (len); j++) {         scanf( %d , &num);         G[num].push_back(i);         in[i]++;         iinn[i]++;       }     }     long long ans = 1ll << 62;     sum = 0;     topsort(1);     ans = min(ans, sum);     sum = 0;     memset(vis, 0, sizeof(vis));     for (int i = (1); i <= (n); i++) iinn[i] = in[i];     topsort(2);     ans = min(ans, sum);     sum = 0;     memset(vis, 0, sizeof(vis));     for (int i = (1); i <= (n); i++) iinn[i] = in[i];     topsort(3);     ans = min(ans, sum);     printf( %lld n , ans);     return 0;   }   