func_code_string: #include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 9;   const int MOD = 1e9 + 7;   const int MAXN = 300005;   long long N, k, m;   long long cook[MAXN], t[MAXN], l[MAXN];   vector<int> ch[MAXN];   int good, bad;   template <class T, class Operation = plus<T>>   struct SegmentTree {     int n;     vector<T> st;     Operation op;     const T identity;     T query(int L, int R) {       T resl = identity, resr = identity;       for (L += n, R += n; L < R; L >>= 1, R >>= 1) {         if (L & 1) resl = op(resl, st[L++]);         if (R & 1) resr = op(st[--R], resr);       }       return op(resl, resr);     }     void update(int p, T val) {       for (st[p += n] = val; p > 1; p >>= 1) st[p >> 1] = op(st[p], st[p ^ 1]);     }     SegmentTree(const vector<T> &A, const T &identity = 0,                 const Operation &op = Operation())         : n((int)A.size()), st(n << 1), op(op), identity(identity) {       copy(A.begin(), A.end(), st.begin() + n);       for (int i = n - 1; i > 0; --i)         st[i] = this->op(st[i << 1], st[i << 1 | 1]);     }   };   struct Op {     pair<long long, long long> operator()(const pair<long long, long long> &a,                                           const pair<long long, long long> &b) {       return pair<long long, long long>(a.first + b.first, a.second + b.second);     }   };   SegmentTree<pair<long long, long long>, Op> st(       vector<pair<long long, long long>>(1000006),       pair<long long, long long>(0, 0));   long long calc(int u) {     pair<long long, long long> val = st.query(t[u], t[u] + 1);     st.update(t[u],               st.op(val, pair<long long, long long>(cook[u], cook[u] * t[u])));     long long maxi1 = 0, maxi2 = 0;     for (int i = 0; i < (int)ch[u].size(); i++) {       if (k - l[ch[u][i]] >= 0) {         k -= l[ch[u][i]];         long long chdp = calc(ch[u][i]);         if (chdp > maxi1) {           maxi2 = maxi1;           maxi1 = chdp;         } else if (chdp > maxi2) {           maxi2 = chdp;         }         k += l[ch[u][i]];       }     }     int lo = 0, hi = min(k + 2, (long long)1000004);     while (lo + 1 < hi) {       int med = lo + (hi - lo) / 2;       pair<long long, long long> sum = st.query(0, med);       if (sum.second > k) {         hi = med;       } else {         lo = med;       }     }     pair<long long, long long> sum = st.query(0, lo);     long long f = sum.first;     if (lo > 0) f += min((k - sum.second) / lo, st.st[st.n + lo].first);     st.update(t[u], val);     if (u == 0) {       return max(f, maxi1);     } else {       return max(f, maxi2);     }   }   int main() {     cin >> N >> k;     for (int i = 0; i < N; i++) {       cin >> cook[i];     }     for (int i = 0; i < N; i++) {       cin >> t[i];     }     for (int i = 1; i < N; i++) {       cin >> m >> l[i];       l[i] *= 2;       ch[m - 1].push_back(i);     }     cout << calc(0) << endl;   }   