func_code_string: #include <bits/stdc++.h>   using namespace std;   vector<long long int> graph[250];   long long int n, a[250];   long long int visit[250];   long long int sol(long long int pos) {     memset(visit, 0, sizeof(visit));     long long int ans = 0;     long long int c = 0;     while (c <= n) {       long long int f = 0;       for (long long int i = 1; i <= n; i++) {         if (a[i] != pos || visit[i]) {           continue;         }         long long int ff = 1;         for (auto p : graph[i]) {           if (!visit[p]) {             ff = 0;             break;           }         }         if (ff) {           f = 1;           ans++;           c++;           visit[i] = 1;         }       }       if (c == n) {         break;       }       if (!f) {         pos++;         ans++;         if (pos == 4) {           pos = 1;         }       }     }     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n;     for (long long int i = 1; i <= n; i++) {       cin >> a[i];     }     for (long long int i = 1; i <= n; i++) {       long long int k;       cin >> k;       for (long long int j = 1; j <= k; j++) {         long long int tl;         cin >> tl;         graph[i].push_back(tl);       }     }     long long int ans = 1e18;     for (long long int i = 1; i <= 3; i++) {       ans = min(ans, sol(i));     }     cout << ans <<   n ;   }   