#include <bits/stdc++.h>   class Scanner {    private:     static const int BUFFER_SIZE = 10000;     char buff[BUFFER_SIZE];     int buffPos, buffLim;       public:     Scanner() {       buffLim = fread(buff, 1, BUFFER_SIZE, stdin);       buffPos = 0;     }       private:     inline void flushBuff() {       buffLim = fread(buff, 1, BUFFER_SIZE, stdin);       if (buffLim == 0) {         buff[buffLim++] =   n ;       }       buffPos = 0;     }     inline bool isWS(char t) { return t ==     || t ==   n ; }     inline bool isDig(char t) { return t >=  0  && t <=  9 ; }     void nextPos() {       buffPos++;       if (buffPos == buffLim) {         flushBuff();       }     }       public:     inline char getchar() {       char ch = buff[buffPos];       nextPos();       return ch;     }     inline void next(char* s) {       while (isWS(buff[buffPos])) {         nextPos();       }       while (!isWS(buff[buffPos])) {         *s = buff[buffPos];         s++;         nextPos();       }       *s =   0 ;     }     inline void nextLine(char* s) {       while (buff[buffPos] !=   n ) {         nextPos();       }       if (buff[buffPos] ==   n ) {         nextPos();       }       while (buff[buffPos] !=   n ) {         *s = buff[buffPos];         s++;         buffPos++;       }       *s =   0 ;     }     inline int nextInt() {       while (!isDig(buff[buffPos]) && buff[buffPos] !=  - ) {         nextPos();       }       int sign = (buff[buffPos] ==  - ) ? nextPos(), -1 : 1;       int res = 0;       while (isDig(buff[buffPos])) {         res = res * 10 + buff[buffPos] -  0 ;         nextPos();       }       return res * sign;     }     inline long long nextLong() {       while (!isDig(buff[buffPos]) && buff[buffPos] !=  - ) {         nextPos();       }       long long sign = (buff[buffPos] ==  - ) ? nextPos(), -1 : 1;       long long res = 0;       while (isDig(buff[buffPos])) {         res = res * 10 + buff[buffPos] -  0 ;         nextPos();       }       return res * sign;     }     inline int n() {       while (buff[buffPos] <  0  || buff[buffPos] >  9 ) {         buffPos++;         if (buffPos == buffLim) {           flushBuff();         }       }       int res = 0;       while (buff[buffPos] >=  0  && buff[buffPos] <=  9 ) {         res = res * 10 + (buff[buffPos] -  0 );         buffPos++;         if (buffPos == buffLim) {           flushBuff();         }       }       return res;     }     inline long long nl() {       while (buff[buffPos] <  0  || buff[buffPos] >  9 ) {         buffPos++;         if (buffPos == buffLim) {           flushBuff();         }       }       long long res = 0;       while (buff[buffPos] >=  0  && buff[buffPos] <=  9 ) {         res = res * 10 + (buff[buffPos] -  0 );         buffPos++;         if (buffPos == buffLim) {           flushBuff();         }       }       return res;     }     inline long long nlm(const int MOD) {       while (buff[buffPos] <  0  || buff[buffPos] >  9 ) {         buffPos++;         if (buffPos == buffLim) {           flushBuff();         }       }       long long res = 0;       while (buff[buffPos] >=  0  && buff[buffPos] <=  9 ) {         res = (res * 10 + (buff[buffPos] -  0 )) % MOD;         buffPos++;         if (buffPos == buffLim) {           flushBuff();         }       }       return res;     }     inline double nextDouble() {       while (isWS(buff[buffPos])) {         nextPos();       }       int sign = (buff[buffPos] ==  - ) ? nextPos(), -1 : 1;       double res = 0;       while (isDig(buff[buffPos])) {         res = res * 10 + buff[buffPos] -  0 ;         nextPos();       }       if (buff[buffPos] ==  . ) {         nextPos();         double ep = 1;         while (isDig(buff[buffPos])) {           ep *= 0.1;           res += ep * (buff[buffPos] -  0 );           nextPos();         }       }       return sign * res;     }     inline char nextChar() {       while (isWS(buff[buffPos])) nextPos();       char res = buff[buffPos];       nextPos();       return res;     }   };   Scanner sc;   template <class _Type>   void logArray(_Type a[], int n) {     for (int i = 0; i < n; ++i) std::cout << a[i] <<    ;     std::cout << std::endl;   }   template <class T>   inline bool checkMin(T& a, T b) {     return (a > b ? a = b, 1 : 0);   }   template <class T>   inline bool checkMax(T& a, T b) {     return (a < b ? a = b, 1 : 0);   }   void preInit();   void init();   void solve();   int32_t main() {     preInit();     init();     solve();     return 0;   }   const int N = 300005;   std::vector<int> e[N];   int col[N], n;   int dp[N], sz[N];   void dfs(int u) {     dp[u] = 1;     sz[u] = (e[u].size() == 0);     for (int v : e[u]) {       dfs(v);       sz[u] += sz[v];     }     if (col[u] == 0) {       for (int v : e[u]) dp[u] += dp[v] - 1;     } else {       for (int v : e[u]) checkMax(dp[u], sz[u] - sz[v] + dp[v]);     }   }   void preInit() {}   void init() {     n = sc.n();     for (int i = 1; i <= n; i++) col[i] = sc.n();     for (int i = 2; i <= n; i++) {       e[sc.n()].push_back(i);     }   }   void solve() {     dfs(1);     printf( %d n , dp[1]);   }