#include <bits/stdc++.h>   using namespace std;   int n, dp[300005], k = 0, b[300005];   vector<int> ke[300005];   void dfs(int u, int par) {     if (ke[u].size() == 1 && u != 1) {       dp[u] = 1;       k++;       return;     }     if (b[u])       dp[u] = 1e9;     else       dp[u] = 0;     for (int v : ke[u])       if (v != par) {         dfs(v, u);         if (b[u])           dp[u] = min(dp[u], dp[v]);         else           dp[u] += dp[v];       }   }   int main() {     ios::sync_with_stdio(0);     cin.tie();     cout.tie();     cin >> n;     for (int i = 1; i <= n; i++) cin >> b[i];     int u;     for (int i = 2; i <= n; i++) {       cin >> u;       ke[u].push_back(i);       ke[i].push_back(u);     }     dfs(1, 0);     cout << k - dp[1] + 1;     return 0;   }   