func_code_string: #include <bits/stdc++.h>   using namespace std;   vector<int> g1[2111];   vector<int> g2[2111];   vector<int> v1, v2;   int s1[1111][1111];   int s2[1111][1111];   int N;   pair<int, int> dfs1(int v) {     pair<int, int> p = {1000, 0};     if (v1[v]) p = {v1[v], v1[v]};     for (auto to : g1[v]) {       auto cur = dfs1(to);       p.first = min(cur.first, p.first);       p.second = max(cur.second, p.second);     }     for (int i = 1; i <= p.first; ++i)       for (int j = p.second; j <= N; ++j) s1[i][j]++;     return p;   }   pair<int, int> dfs2(int v) {     pair<int, int> p = {1000, 0};     if (v2[v]) p = {v2[v], v2[v]};     for (auto to : g2[v]) {       auto cur = dfs2(to);       p.first = min(cur.first, p.first);       p.second = max(cur.second, p.second);     }     for (int i = 1; i <= p.first; ++i)       for (int j = p.second; j <= N; ++j) s2[i][j]++;     return p;   }   int dp[1111];   int main() {     cin >> N;     int n1;     cin >> n1;     for (int i = 2; i <= n1; ++i) {       int t;       cin >> t;       g1[t].push_back(i);     }     v1.assign(n1 + 1, 0);     for (int i = 1; i <= N; ++i) {       int t;       cin >> t;       v1[t] = i;     }     int n2;     cin >> n2;     for (int i = 2; i <= n2; ++i) {       int t;       cin >> t;       g2[t].push_back(i);     }     v2.assign(n2 + 1, 0);     for (int i = 1; i <= N; ++i) {       int t;       cin >> t;       v2[t] = i;     }     dfs1(1);     dfs2(1);     for (int i = 1; i <= N; ++i) {       for (int j = 1; j <= N; ++j) {         s1[i][j] = min(s1[i][j], n1 - 1);         s2[i][j] = min(s2[i][j], n2 - 1);       }     }     for (int i = 1; i <= N; ++i) {       int mx1 = s1[1][i];       int mx2 = s2[1][i];       dp[i] = max(mx1, mx2);       for (int j = i; j >= 2; --j) {         {           int cur = s1[j][i];           dp[i] = max(dp[i], dp[j - 1] + cur);         }         {           int cur = s2[j][i];           dp[i] = max(dp[i], dp[j - 1] + cur);         }       }     }     cout << dp[N] << endl;   }   