func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int K = 1048576;   int n;   long long t[2][2 * K];   vector<int> g[N];   int T[N];   long long h[N], x[N], dp[N];   long long total;   void build() {     for (int i = 0; i < 2 * K; i++) t[0][i] = t[1][i] = 0;   }   void upd(int id, long long X, int type) {     id += K - 1;     while (id > 0) {       t[type][id] += X;       id /= 2;     }   }   long long get(int L, int R, int type) {     if (R == 0)       return 0;     else if (type == 0 && R == K)       return 2e18;     L += K - 1;     R += K - 1;     long long res = 0;     while (L <= R) {       if (L % 2 == 1) res += t[type][L++];       if (R % 2 == 0) res += t[type][R--];       L /= 2;       R /= 2;     }     return res;   }   void dfs(int v) {     upd(T[v], x[v] * T[v], 0);     upd(T[v], x[v], 1);     int l = 1, r = K;     while (l + 1 < r) {       int mid = (l + r) / 2;       if (h[v] + h[v] + get(1, mid - 1, 0) <= total)         l = mid;       else         r = mid;     }     dp[v] = get(1, l - 1, 1);     long long residue = total - get(1, l - 1, 0) - h[v] - h[v];     dp[v] += min(t[0][l + K - 1], residue) / l;     for (int u : g[v]) {       h[u] += h[v];       dfs(u);     }     if (v == 1) {       for (int u : g[v]) dp[v] = max(dp[v], dp[u]);     } else {       long long max1 = 0, max2 = 0;       for (int u : g[v]) {         if (dp[u] > max1) {           max2 = max1;           max1 = dp[u];         } else if (dp[u] > max2) {           max2 = dp[u];         }       }       dp[v] = max(dp[v], max2);     }     upd(T[v], -x[v] * T[v], 0);     upd(T[v], -x[v], 1);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> total;     for (int i = 1; i <= n; i++) cin >> x[i];     for (int i = 1; i <= n; i++) cin >> T[i];     for (int i = 2; i <= n; i++) {       int parent;       cin >> parent >> h[i];       g[parent].push_back(i);     }     build();     h[1] = 0;     dfs(1);     cout << dp[1] <<   n ;     return 0;   }   