5
27468 7465 74275 40573 40155
112071 76270 244461 264202 132397
1 777133331
2 107454154
3 652330694
4 792720519
 5
78188 56310 79021 70050 65217
115040 5149 128449 98357 36580
1 451393770
2 574046602
3 590130784
4 112514248
 7
1 1 1 1 1 1 1
1 3000000000 3000000000 3000000000 1000000000 1000000000 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
 10
2 8 6 1 2 7 6 9 2 8
4 9 4 3 5 2 9 3 7 3
1 8
2 8
3 8
4 10
5 1
6 4
7 3
8 10
9 2
 11
1 1 1 1 1 1 1 1 1 1 1
1 1000000001 1000000001 1000000001 1000000001 1000000001 1000000001 1000000001 1000000001 1000000001 1000000001
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
 5
2 1 1 2 3
1 2 2 2 1
1 2
1 3
2 4
1 4

NO
 NO
 NO
 YES
 NO
 NO

#include <iostream>
#include <fstream>
#include <list>
#include <cstdlib>
#define fi first
#define se second
using namespace std;
typedef pair<int,int> ii;
const double INF = 1e17;
const int N = 1e5;

int n,par[N+1],parc[N+1],lev[N+1];
long long a[N+1], b[N+1];
bool lock[N+1];

void enter()
{
    cin >> n;
    for(int i=1; i<=n; ++i) cin >> b[i];
    for(int i=1; i<=n; ++i) cin >> a[i];
    for(int i=2; i<=n; ++i) {
        cin >> par[i] >> parc[i];
        ++lev[par[i]];
    }
}
void topo(int x)
{
    lock[x] = 1;
    if (x==1)
    {
        //cout << b[x];
        cout << (a[x]<=b[x] ? "YES" : "NO");
        exit(0);
    }
    if (a[x]<=b[x])
    {
        b[par[x]] += b[x]-a[x];
        b[x] = a[x];
    }
    else
    {
        double temp = (a[x]-b[x])*parc[x] - b[par[x]];
        if (temp > INF) { cout << "NO"; exit(0); }
        b[par[x]] -= (a[x]-b[x])*parc[x];
    }

    --lev[par[x]];
    if (!lev[par[x]]) topo(par[x]);
}

int main()
{
    ios_base::sync_with_stdio(0);
    enter();
    for(int x=1; x<=n; ++x)
    if (!lock[x] && !lev[x])
        topo(x);
}
