#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int mod2 = 1e9 + 9;   inline int pow_(long long a, int n, int p = mod) {     int r = 1;     while (n) {       if (n & 1) r = r * a % p;       n >>= 1;       a = a * a % p;     }     return r;   }   int main(void) {     int n, l;     long long s;     cin >> n >> l >> s;     int w[n + 1], p[n + 1];     memset(p, 0, sizeof(p));     memset(w, 0, sizeof(w));     for (int i = 1; i <= n; i++) cin >> w[i];     for (int i = 2; i <= n; i++) cin >> p[i];     bool done[n + 1];     memset(done, false, sizeof(done));     for (int i = 1; i <= n; i++)       if (w[i] > s) return 0 * printf( -1 n );     int ans = 0;     for (int i = n; i >= 1; i--) {       if (done[i]) continue;       ans++;       int cur = i;       int L = l;       long long S = s;       while (cur and L > 0 and S >= w[cur]) {         done[cur] = true;         S -= w[cur];         L--;         cur = p[cur];       }     }     cout << ans <<   n ;   }   