[TASK]:
You will be given lines of pseudocode, your task is to write the corresponding C++ code. The pseudocode will provide detailed description of the c++ code line by line. The pseudocode is garanteed to be correct and complete.

[INSTRUCTION]:
The following libraries are already included in the code.
```cpp
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <fstream>
#include <climits>
#include <cassert>
#include <iomanip>
#include <sstream>
#include <bitset>
using namespace std;
```
Do not include them in your code again. Please surround your code with ```cpp and ``` markers. Note that the code should correspond to the pseudocode line by line.

[PSEUDOCODE]:
function desperate_optimization (get precision as int)
    use normal notation
    show decimal point
    set precision digits
end of the block
vec=vector of 250 int
q=array of 3 queue of int
qq=array of 3 queue of int
type=array of 250 int
outt = array of 250 int
toutt = array of 250 int
define the main function
    desperate_optimization(20)
    n=int
    read n
    for i=1 to n inclusive read type[i]
    for i=1 to n inclusive
        decrement type[i]
        x=int
        read x
        outt[i] = x
        while decremented x > 0
            u=int
            read u
            add i to end of vec[u]
        end of the block
    end of the block
    for i=1 to n inclusive
        if outt[i] is 0 push i into q[type[i]]
    start=0
    for i=0 to 3 exclusive qq[i]=q[i]
    for i=1 to n inclusive toutt[i]=outt[i]
    ans=1000000000
    for i=0 to 3 exclusive
        if qq[i] is empty continue
        for j=0 to 3 exclusive q[j]=qq[j]
        for j=1 to n inclusive outt[j]=toutt[j]
        start=i
        total=0
        while q[0], q[1] and q[2] are not empty
            while q[start] is not empty
                pos=first item of q[start]
                pop q[start]
                for i=0 to size of vec[pos] exclusive
                    nx=vec[pos][i]
                    decrement outt[nx]
                    if outt[nx] is 0 push nx into q[type[nx]]
                end of the block
                increment total
            end of the block
            start=(start+1) modulo 3
            increment total
        end of the block
        ans=min(ans, total-1)
    end of the block
    print ans
    return to indicate successful execution
end of the block

[CODE]:

void desperate_optimization(int precision) {
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(precision);
}
vector<int> vec[250];
queue<int> q[3];
queue<int> qq[3];
int type[250];
int outt[250];
int toutt[250];
int main() {
    desperate_optimization(20);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> type[i];
    for (int i = 1; i <= n; i++) {
        type[i]--;
        int x;
        cin >> x;
        outt[i] = x;
        while (x--) {
            int u;
            cin >> u;
            vec[u].push_back(i);
        }
    }
    for (int i = 1; i <= n; i++)
        if (outt[i] == 0) q[type[i]].push(i);
    int start = 0;
    for (int i = 0; i < 3; i++) qq[i] = q[i];
    for (int i = 1; i <= n; i++) toutt[i] = outt[i];
    int ans = 1e9;
    for (int i = 0; i < 3; i++) {
        if (qq[i].empty() == true) continue;
        for (int j = 0; j < 3; j++) q[j] = qq[j];
        for (int j = 1; j <= n; j++) outt[j] = toutt[j];
        start = i;
        int total = 0;
        while (!q[0].empty() || !q[1].empty() || !q[2].empty()) {
            while (!q[start].empty()) {
                int pos = q[start].front();
                q[start].pop();
                for (int i = 0; i < vec[pos].size(); i++) {
                    int nx = vec[pos][i];
                    outt[nx]--;
                    if (outt[nx] == 0) q[type[nx]].push(nx);
                }
                total++;
            }
            start = (start + 1) % 3;
            total++;
        }
        ans = min(ans, total - 1);
    }
    cout << ans << '\n';
    return 0;
}