#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

int32_t main(){
	IOS;
	int t;
	cin >> t;
	while(t--){
		int a, b;
		cin >> a >> b;
		int ini = 0;
		while( true ){
			if( b > a )
				swap(a, b);
			int dif = min((a-b)/2, b);
			if( dif == 0 )
				break;
			ini = ini + dif;
			a = a - dif*2;
			b = b - dif;
			// cout << "iter " << ini << " " << a << " " << b << " df " << dif << endl;
		}
		// cout << ini << " " << a << " " << b << endl;
		int tot = min(a, b);
		tot = (tot/3);
		a = a - tot*3;
		b = b - tot*3;
		ini = ini + tot*2;
		// cout << "ini " << ini << " " << a <<  " " << b << endl;
		while( true ){
			if( a == 0 || b == 0 || ( a < 2 && b < 2 ))
				break;
			if( b > a )
				swap(a, b);
			a = a - 2;
			b = b - 1;
			ini++;
		}

		cout << ini << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef   long  double ld;
#define syncboost ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define mp make_pair
#define pb push_back
#define pp pop_back
#define pl pair<ll,ll>
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vpl vector<pair<ll,ll>>
#define all(x) x.begin(),x.end()
#define precise(n) cout << fixed; cout << setprecision(n)
#define forn(i, n) for (ll i = 0; i < ll(n); i++)
#define setbit(x) __builtin_popcount(x)
#define run(i, v) for(auto &i: v)
#define hike(i, v) for(const auto &i: v)
#define srt(v) sort(v.begin(),v.end())
#define mem(x,val) memset(x,val,sizeof(x))
#define rep(i,init,n) for(ll i = init;i<n;i++)
#define rrep(i,n,init) for(ll i = n;i>=init;i--)
#define fi first
#define se second
double pi = 3.14159265;
#define show(x) cerr << x
#define deb(x) show(#x << ": " << (x) << endl);
#define det(x) cout<<x<<"\n";
#define No cout<<"No\n";
#define Yes cout<<"Yes\n";
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define sp " "
#define nl cout<<"\n";
#define ps(x,y)   fixed<<setprecision(y)<<x
ll MOD = 1e9+7;
const ll mod  =998244353;
inline ll add(ll x, ll y) { x += y; if (x >= MOD) x -= MOD; return x; }
inline ll sub(ll x, ll y) { x -= y; if (x < 0) x += MOD; return x; }
inline ll mul(ll x, ll y) { return (x * y) % MOD; }
inline ll powr(ll a, ll b) {
     ll x = 1 % MOD;
     while (b) {
          if (b & 1) x = mul(x, a);
          a = mul(a, a);
          b >>= 1;
     }
     return x;
}
inline ll modinv(ll x) {
    return powr(x,MOD-2);
}

inline ll inv(ll a) { return powr(a, MOD - 2); }
const ll N = 500005;
const ll maxn = 1e9+1;
const ll INF = ll(1e18);
ll dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

int n, m;
int ans[N];

int lasar[N];
vector <int> G[N];
vector <int> in[N];
vl ct;
void precomp()
{

}
void solve(){
   ll n,k;
    cin>>n>>k;
    if(n<k)
    {
      swap(n,k);

    }
    ll ans = min(k,n/2);
    ll rem = k-ans;
    if(rem>=2 && (rem+1)%2 ==0)
     ans--,ans += (rem+1)/2;
   cout<<ans;
   nl
    return;
}
void io()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
}
signed main()
{
    ll t = 1;

syncboost;
  // io();
//
    cin>>t;
    //precomp();
   //precise(6);
   rep(testcase,1,t+1)
    {
    //  deb(testcase);

     //  cout<<"Case #"<<testcase<<": ";
       solve();
       //nl
    }

   return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef   long  double ld;
#define syncboost ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define mp make_pair
#define pb push_back
#define pp pop_back
#define pl pair<ll,ll>
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vpl vector<pair<ll,ll>>
#define all(x) x.begin(),x.end()
#define precise(n) cout << fixed; cout << setprecision(n)
#define forn(i, n) for (ll i = 0; i < ll(n); i++)
#define setbit(x) __builtin_popcount(x)
#define run(i, v) for(auto &i: v)
#define hike(i, v) for(const auto &i: v)
#define srt(v) sort(v.begin(),v.end())
#define mem(x,val) memset(x,val,sizeof(x))
#define rep(i,init,n) for(ll i = init;i<n;i++)
#define rrep(i,n,init) for(ll i = n;i>=init;i--)
#define fi first
#define se second
double pi = 3.14159265;
#define show(x) cerr << x
#define deb(x) show(#x << ": " << (x) << endl);
#define det(x) cout<<x<<"\n";
#define No cout<<"No\n";
#define Yes cout<<"Yes\n";
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define sp " "
#define nl cout<<"\n";
#define ps(x,y)   fixed<<setprecision(y)<<x
ll MOD = 1e9+7;
const ll mod  =998244353;
inline ll add(ll x, ll y) { x += y; if (x >= MOD) x -= MOD; return x; }
inline ll sub(ll x, ll y) { x -= y; if (x < 0) x += MOD; return x; }
inline ll mul(ll x, ll y) { return (x * y) % MOD; }
inline ll powr(ll a, ll b) {
     ll x = 1 % MOD;
     while (b) {
          if (b & 1) x = mul(x, a);
          a = mul(a, a);
          b >>= 1;
     }
     return x;
}
inline ll modinv(ll x) {
    return powr(x,MOD-2);
}

inline ll inv(ll a) { return powr(a, MOD - 2); }
const ll N = 500005;
const ll maxn = 1e9+1;
const ll INF = ll(1e18);
ll dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

int n, m;
int ans[N];

int lasar[N];
vector <int> G[N];
vector <int> in[N];
vl ct;
void precomp()
{

}
void solve(){
   ll n,k,a,b;
    cin>>a>>b;
    if(a<b)
    {
      swap(a,b);

    }
    if(a>=2*b)
      cout<<b<<"\n";
    else
    {
      if(a%b==0)
       cout<<min(b,a/2)<<"\n";
     else
        cout<<min(b,a/2)+1<<"\n";
    }
    return;
}
void io()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
}
signed main()
{
    ll t = 1;

syncboost;
  // io();
//
    cin>>t;
    //precomp();
   //precise(6);
   rep(testcase,1,t+1)
    {
    //  deb(testcase);

     //  cout<<"Case #"<<testcase<<": ";
       solve();
       //nl
    }

   return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef   long  double ld;
#define syncboost ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define mp make_pair
#define pb push_back
#define pp pop_back
#define pl pair<ll,ll>
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vpl vector<pair<ll,ll>>
#define all(x) x.begin(),x.end()
#define precise(n) cout << fixed; cout << setprecision(n)
#define forn(i, n) for (ll i = 0; i < ll(n); i++)
#define setbit(x) __builtin_popcount(x)
#define run(i, v) for(auto &i: v)
#define hike(i, v) for(const auto &i: v)
#define srt(v) sort(v.begin(),v.end())
#define mem(x,val) memset(x,val,sizeof(x))
#define rep(i,init,n) for(ll i = init;i<n;i++)
#define rrep(i,n,init) for(ll i = n;i>=init;i--)
#define fi first
#define se second
double pi = 3.14159265;
#define show(x) cerr << x
#define deb(x) show(#x << ": " << (x) << endl);
#define det(x) cout<<x<<"\n";
#define No cout<<"No\n";
#define Yes cout<<"Yes\n";
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define sp " "
#define nl cout<<"\n";
#define ps(x,y)   fixed<<setprecision(y)<<x
ll MOD = 1e9+7;
const ll mod  =998244353;
inline ll add(ll x, ll y) { x += y; if (x >= MOD) x -= MOD; return x; }
inline ll sub(ll x, ll y) { x -= y; if (x < 0) x += MOD; return x; }
inline ll mul(ll x, ll y) { return (x * y) % MOD; }
inline ll powr(ll a, ll b) {
     ll x = 1 % MOD;
     while (b) {
          if (b & 1) x = mul(x, a);
          a = mul(a, a);
          b >>= 1;
     }
     return x;
}
inline ll modinv(ll x) {
    return powr(x,MOD-2);
}

inline ll inv(ll a) { return powr(a, MOD - 2); }
const ll N = 500005;
const ll maxn = 1e9+1;
const ll INF = ll(1e18);
ll dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

int n, m;
int ans[N];

int lasar[N];
vector <int> G[N];
vector <int> in[N];
vl ct;
void precomp()
{

}
void solve(){
   ll n,k,a,b;
    cin>>a>>b;
    if(a<b)
    {
      swap(a,b);

    }

     ll ans = min(b/2,a/2);
      a -= ans*2;
      b-=ans;
      if(a<b)
        swap(a,b);
      ans += min(b,a/2);
      cout<<ans;
      nl

    return;
}
void io()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
}
signed main()
{
    ll t = 1;

syncboost;
  // io();
//
    cin>>t;
    //precomp();
   //precise(6);
   rep(testcase,1,t+1)
    {
    //  deb(testcase);

     //  cout<<"Case #"<<testcase<<": ";
       solve();
       //nl
    }

   return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef   long  double ld;
#define syncboost ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define mp make_pair
#define pb push_back
#define pp pop_back
#define pl pair<ll,ll>
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vpl vector<pair<ll,ll>>
#define all(x) x.begin(),x.end()
#define precise(n) cout << fixed; cout << setprecision(n)
#define forn(i, n) for (ll i = 0; i < ll(n); i++)
#define setbit(x) __builtin_popcount(x)
#define run(i, v) for(auto &i: v)
#define hike(i, v) for(const auto &i: v)
#define srt(v) sort(v.begin(),v.end())
#define mem(x,val) memset(x,val,sizeof(x))
#define rep(i,init,n) for(ll i = init;i<n;i++)
#define rrep(i,n,init) for(ll i = n;i>=init;i--)
#define fi first
#define se second
double pi = 3.14159265;
#define show(x) cerr << x
#define deb(x) show(#x << ": " << (x) << endl);
#define det(x) cout<<x<<"\n";
#define No cout<<"No\n";
#define Yes cout<<"Yes\n";
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define sp " "
#define nl cout<<"\n";
#define ps(x,y)   fixed<<setprecision(y)<<x
ll MOD = 1e9+7;
const ll mod  =998244353;
inline ll add(ll x, ll y) { x += y; if (x >= MOD) x -= MOD; return x; }
inline ll sub(ll x, ll y) { x -= y; if (x < 0) x += MOD; return x; }
inline ll mul(ll x, ll y) { return (x * y) % MOD; }
inline ll powr(ll a, ll b) {
     ll x = 1 % MOD;
     while (b) {
          if (b & 1) x = mul(x, a);
          a = mul(a, a);
          b >>= 1;
     }
     return x;
}
inline ll modinv(ll x) {
    return powr(x,MOD-2);
}

inline ll inv(ll a) { return powr(a, MOD - 2); }
const ll N = 500005;
const ll maxn = 1e9+1;
const ll INF = ll(1e18);
ll dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

int n, m;
int ans[N];

int lasar[N];
vector <int> G[N];
vector <int> in[N];
vl ct;
void precomp()
{

}
void solve(){
   ll n,k;
    cin>>n>>k;
    if(n<k)
    {
      swap(n,k);

    }
    ll ans = min(k,n/2);
    ll rem = k-ans;
    if(rem>2)
     ans--,ans += (rem+1)/2;
   cout<<ans;
   nl
    return;
}
void io()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
}
signed main()
{
    ll t = 1;

syncboost;
  // io();
//
    cin>>t;
    //precomp();
   //precise(6);
   rep(testcase,1,t+1)
    {
    //  deb(testcase);

     //  cout<<"Case #"<<testcase<<": ";
       solve();
       //nl
    }

   return 0;
}


#include<bits/stdc++.h>

using namespace std;

int solve(int a, int b)
{
	if(a==0 || b==0)
	{
		return 0;
	}

	if(a == 1 || b == 1)
	{
		return 1;
	}

    return min((a+b)/3,a,b);

}

int main()
{
	int t;
	cin >>t;
	while(t--)
	{
		int a,b;
		cin >>a>>b;
		cout<<solve(a,b)<<endl;
	}
}


#include<bits/stdc++.h>

using namespace std;

long long solve(long long a, long long b)
{
    return min((a+b)/3,min(a,b));

}

int main()
{
	long long t;
	cin >>t;
	while(t--)
	{
		long long a,b;
		cin >>a>>b;
		cout<<solve(a,b)<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define int long long;

int solve(int a, int b)
{
	if(a==0 || b==0)
	{
		return 0;
	}

	if(a == 1 || b == 1)
	{
		return 1;
	}

    int x = (2*a - b)/3;
    int y = (2*b - a)/3;
    return x+y;

}

int32_t main()
{
	int t;
	cin >>t;
	while(t--)
	{
		int a,b;
		cin >>a>>b;
		cout<<solve(a,b)<<endl;
	}
}


#include<bits/stdc++.h>

using namespace std;
using ll = long long;

ll solve(ll a, ll b)
{
	if(a==0 || b==0)
	{
		return 0;
	}

	if(a == 1 || b == 1)
	{
		return 1;
	}

    ll x = (2*a - b)/3;
    ll y = (2*b - a)/3;
    return x+y;

}

int main()
{
	ll t;
	cin >>t;
	while(t--)
	{
		ll a,b;
		cin >>a>>b;
		cout<<solve(a,b)<<endl;
	}
}


#include<bits/stdc++.h>
#define MAXN 100005
#define LL long long
#define len(l,r) (r-l+1)
#define P int(998244353)
#define LD long double
#define INF (LL)(1e18)
using namespace std;

int N;
LL a[MAXN], b[MAXN];

struct Edge{
	int v,k;
	Edge(int v=0, int k=0):v(v), k(k){}
};

vector<Edge> adj[MAXN];

void dfs(int u){

	for(int v,w,k=0;k<adj[u].size();k++){
		v = adj[u][k].v;
		w = adj[u][k].k;

		dfs(v);
		if(b[v] >= a[v]) b[u] += b[v] - a[v];
		else{
			if((INF+a[u])/w <= a[v] - b[v]) b[1] = -INF;
			else b[u] -= w*(a[v] - b[v]);
		}
	}
}

int main(){
	cin>>N;
	for(int i=1;i<=N;i++) cin>>b[i];
	for(int i=1;i<=N;i++) cin>>a[i];

	for(int u,k,v=2;v<=N;v++){
		cin>>u>>k;

		adj[u].push_back(Edge(v,k));
	}

	dfs(1);
//	for(int i=1;i<=N;i++){
//		cout<<i<<" "<<b[i]<<" "<<a[i]<<endl;
//	}
//
	if(b[1]>=a[1]) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;

	return 0;
}


#include<bits/stdc++.h>
#define MAXN 100005
#define LL long long
#define len(l,r) (r-l+1)
#define P int(998244353)
#define LD long double
#define INF (LL)(1e15)
using namespace std;

int N;
LL a[MAXN], b[MAXN];

struct Edge{
	int v,k;
	Edge(int v=0, int k=0):v(v), k(k){}
};

vector<Edge> adj[MAXN];

void dfs(int u){

	for(int v,w,k=0;k<adj[u].size();k++){
		v = adj[u][k].v;
		w = adj[u][k].k;

		dfs(v);
		if(b[v] >= a[v]) b[u] += b[v] - a[v];
		else{
			if((INF+a[u])/w <= a[v] - b[v]) b[1] = -INF;
			else b[u] -= w*(a[v] - b[v]);
		}
	}
}

int main(){
	cin>>N;
	for(int i=1;i<=N;i++) cin>>b[i];
	for(int i=1;i<=N;i++) cin>>a[i];

	for(int u,k,v=2;v<=N;v++){
		cin>>u>>k;

		adj[u].push_back(Edge(v,k));
	}

	dfs(1);
//	for(int i=1;i<=N;i++){
//		cout<<i<<" "<<b[i]<<" "<<a[i]<<endl;
//	}
//
	if(b[1]>=a[1]) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

long long a[100010], b[100010], k[100010];
vector <int> from[100010];

long long dfs(int x){
	long long sum = b[x];
	for (int i = 0; i < from[x].size(); i++){
		int v = from[x][i];
		sum += dfs(v);
	}
	if (x == 1) return sum;
	long long res = 0;
	if (sum > a[x]) res = (sum - a[x] + k[x] - 1) / k[x], sum -= res * k[x];
	res -= a[x] - sum;
	return res;
}

int main(){
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; i++){
		scanf("%lld", &a[i]);
	}
	for (int i = 1; i <= n; i++){
		scanf("%lld", &b[i]);
	}
	for (int i = 2; i <= n; i++){
		int x; scanf("%d%d", &x, &k[i]);
		from[x].push_back(i);
	}
	printf(dfs(1) >= 0 ? "YES\n" : "NO\n");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const long long INF = 100000000000000000;

long long a[100010], b[100010], k[100010];
vector <int> from[100010];

long long dfs(int x){
	long long sum = a[x] - b[x];
	for (int i = 0; i < from[x].size(); i++){
		int v = from[x][i];
		long long val = dfs(v);
		sum += val;
		if (sum < -INF) sum = -INF;
	}
	if (x == 1) return sum;
	if (sum < 0){
		if (INF / k[x] > -sum) sum *= k[x];
		else sum = -INF;
	}
	return sum;
}

int main(){
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; i++){
		scanf("%lld", &a[i]);
	}
	for (int i = 1; i <= n; i++){
		scanf("%lld", &b[i]);
	}
	for (int i = 2; i <= n; i++){
		int x; scanf("%d%lld", &x, &k[i]);
		from[x].push_back(i);
	}
	printf(dfs(1) >= 0 ? "YES\n" : "NO\n");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

long long a[100010], b[100010], k[100010];
vector <int> from[100010];

long long dfs(int x){
	long long sum = b[x];
	for (int i = 0; i < from[x].size(); i++){
		int v = from[x][i];
		sum += dfs(v);
	}
	long long res = 0;
	if (sum > a[x]) res = (sum - a[x] + k[x] - 1) / k[x], sum -= res * k[x];
	res -= a[x] - sum;
	return res;
}

int main(){
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; i++){
		scanf("%lld", &a[i]);
	}
	for (int i = 1; i <= n; i++){
		scanf("%lld", &b[i]);
	}
	for (int i = 2; i <= n; i++){
		int x; scanf("%d%d", &x, &k[i]);
		from[x].push_back(i);
	}
	printf(dfs(1) >= 0 ? "NO\n" : "YES\n");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

long long a[100010], b[100010], k[100010];
vector <int> from[100010];

long long dfs(int x){
	long long sum = b[x];
	for (int i = 0; i < from[x].size(); i++){
		int v = from[x][i];
		sum += dfs(v);
	}
	long long res = 0;
	if (sum > a[x]) res = (sum - a[x] + k[x] - 1) / k[x], sum -= res * k[x];
	res -= a[x] - sum;
	return res;
}

int main(){
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; i++){
		scanf("%lld", &a[i]);
	}
	for (int i = 1; i <= n; i++){
		scanf("%lld", &b[i]);
	}
	for (int i = 2; i <= n; i++){
		int x; scanf("%d%d", &x, &k[i]);
		from[x].push_back(i);
	}
	printf(dfs(1) ? "NO\n" : "YES\n");
	return 0;
}


#include <iostream>
#include <cstdio>
#define int long long
using namespace std;
int a[100005],b[100005],head[100005],cnt;
struct edge
{
	int v,w,n;
}e[200005];
inline void add(int u,int v,int w)
{
	e[++cnt]={v,w,head[u]};
	head[u]=cnt;
}
int dp[100005];
inline void dfs(int u)
{
	dp[u]=a[u];
	for(int i=head[u];i;i=e[i].n)
	{
		dfs(e[i].v);
		if(dp[e[i].v]>=0) dp[u]+=dp[e[i].v];
		else
		{
			double x=dp[u];
			x+=(double)dp[e[i].v]*(double)(e[i].w);
			if(x<-3e18)
			{
				puts("NO");
				exit(0);
			}
			dp[u]+=dp[e[i].v]*e[i].w;
		}
	}
}
signed main(int argc, char** argv) {
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&b[i]);
		a[i]-=b[i];
	}
	for(int i=2;i<=n;i++)
	{
		int f,w;
		scanf("%lld%lld",&f,&w);
		add(f,i,w);
	}
	dfs(1);
	if(dp[1]>=0)
	{
		puts("YES");
	}else puts("NO");
	return 0;
}


#include <iostream>
#include <cstdio>
#define int long long
using namespace std;
int a[100005],b[100005],head[100005],cnt;
struct edge
{
	int v,w,n;
}e[200005];
inline void add(int u,int v,int w)
{
	e[++cnt]={v,w,head[u]};
	head[u]=cnt;
}
int dp[100005];
inline void dfs(int u)
{
	dp[u]=a[u];
	for(int i=head[u];i;i=e[i].n)
	{
		dfs(e[i].v);
		if(dp[e[i].v]>=0) dp[u]+=dp[e[i].v];
		else dp[u]+=dp[e[i].v]*e[i].w;
	}
}
signed main(int argc, char** argv) {
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&b[i]);
		a[i]-=b[i];
	}
	for(int i=2;i<=n;i++)
	{
		int f,w;
		scanf("%lld%lld",&f,&w);
		add(f,i,w);
	}
	dfs(1);
	if(dp[1]>=0)
	{
		puts("YES");
	}else puts("NO");
	return 0;
}


#include <iostream>
#include <cstdio>
#define int long long
using namespace std;
int a[100005],b[100005],head[100005],cnt;
struct edge
{
	int v,w,n;
}e[200005];
inline void add(int u,int v,int w)
{
	e[++cnt]={v,w,head[u]};
	head[u]=cnt;
}
int dp[100005];
inline void dfs(int u)
{
	dp[u]=a[u];
	for(int i=head[u];i;i=e[i].n)
	{
		dfs(e[i].v);
		if(dp[e[i].v]>=0) dp[u]+=dp[e[i].v];
		else
		{
			double x=dp[u];
			x+=(double)dp[e[i].v]*(double)(e[i].v);
			if(x<-3e18)
			{
				puts("NO");
				exit(0);
			}
			dp[u]+=dp[e[i].v]*e[i].w;
		}
	}
}
signed main(int argc, char** argv) {
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&b[i]);
		a[i]-=b[i];
	}
	for(int i=2;i<=n;i++)
	{
		int f,w;
		scanf("%lld%lld",&f,&w);
		add(f,i,w);
	}
	dfs(1);
	if(dp[1]>=0)
	{
		puts("YES");
	}else puts("NO");
	return 0;
}


#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#define lo(i, n, m) for (int i = n; i < m; i++)
#define loe(i, n, m) for (int i = n; i <= m; i++)
#define pb push_back
#define mk make_pair
#define clr(a, b) memset((a), (b), sizeof(a))
typedef long long LL;
using namespace std;
// const int INF = 0x3f3f3f3f;
// const int INF = 0x7fffffff;
// const LL INF = 0x3f3f3f3f3f3f3f3f;
// const LL INF = 0x7fffffffffffffff;
const int NIL = -1;
template <class T>
inline T mx(T a, T b) {return a > b ? a : b;}
template <class T>
inline T mi(T a, T b) {return a < b ? a : b;}
template <class T>
inline void sw(T &a, T &b) {
    T t = a; a = b; b = t;
}
template <class T>
inline T mabs(T x) {return x < 0 ? -x : x;}
inline char gc() {
    char ret;
    while ((ret = getchar()) == ' ' || ret == '\n' || ret == '\t');
    return ret;
}

const int LIM = 1e5 + 10;
int n;
LL a[LIM], b[LIM];
typedef pair<int, LL> EDG;
vector<EDG> adj[LIM];

bool dfs(int crt, LL sum, bool flag, LL pre, int fa) {
    vector<EDG> &t = adj[crt];
    lo(i, 0, t.size()) {
        bool f;
        if (sum * t[i].second < 0) f = dfs(t[i].first, sum * t[i].second, true, t[i].second, crt);
        else f = dfs(t[i].first, sum * t[i].second, false, t[i].second, crt);
        if (!f) return false;
    }
    if (crt == 1) {
        return a[crt] == b[crt];
    }
    if (b[crt] > a[crt]) {
        LL dif = b[crt] - a[crt];
        if (dif * pre < 0) return false;
        LL need = dif * pre;
        if (need <= a[crt]) {
            a[fa] -= need, a[crt] += dif;
            return true;
        } else {
            LL tmp = a[fa];
            a[fa] = tmp % pre, a[crt] += tmp / pre, dif -= tmp / pre;
            if (flag || dif * sum < 0) return false;
            need = dif * sum;
            if (a[1] < need) return false;
            a[1] -= need, a[crt] += dif;
            return true;
        }
    } else if (b[crt] < a[crt]) {
        LL dif = a[crt] - b[crt];
        a[crt] -= dif, a[fa] += dif;
        return true;
    }
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    cin >> n;
    loe(i, 1, n) cin >> a[i];
    loe(i, 1, n) cin >> b[i];
    int v;
    LL w;
    loe(i, 2, n) {
        cin >> v >> w;
        adj[v].pb(mk(i, w));
    }
    cout << (dfs(1, 1, false, 0, -1) ? "YES" : "NO");
    return 0;
}


#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#define lo(i, n, m) for (int i = n; i < m; i++)
#define loe(i, n, m) for (int i = n; i <= m; i++)
#define pb push_back
#define mk make_pair
#define clr(a, b) memset((a), (b), sizeof(a))
typedef long long LL;
using namespace std;
// const int INF = 0x3f3f3f3f;
// const int INF = 0x7fffffff;
// const LL INF = 0x3f3f3f3f3f3f3f3f;
// const LL INF = 0x7fffffffffffffff;
const int NIL = -1;
template <class T>
inline T mx(T a, T b) {return a > b ? a : b;}
template <class T>
inline T mi(T a, T b) {return a < b ? a : b;}
template <class T>
inline void sw(T &a, T &b) {
    T t = a; a = b; b = t;
}
template <class T>
inline T mabs(T x) {return x < 0 ? -x : x;}
inline char gc() {
    char ret;
    while ((ret = getchar()) == ' ' || ret == '\n' || ret == '\t');
    return ret;
}

const int LIM = 1e5 + 10;
int n;
LL a[LIM], b[LIM];
typedef pair<int, LL> EDG;
vector<EDG> adj[LIM];

bool dfs(int crt, LL pre, int fa) {
    vector<EDG> &t = adj[crt];
    // cout << crt << endl;
    lo(i, 0, t.size()) if (!dfs(t[i].first, t[i].second, crt)) return false;
    if (crt == 1) return a[crt] >= b[crt];
    // if (a[crt] < 0) return false;
    if (b[crt] > a[crt]) {
        LL dif = b[crt] - a[crt];
        if (dif * pre < 0) return false;
        LL need = dif * pre;
        a[crt] += dif, a[fa] -= need;
        return true;
    } else if (b[crt] < a[crt]) {
        // cout << "< " << crt << " : " << a[crt] << endl;
        LL dif = a[crt] - b[crt];
        a[crt] -= dif, a[fa] += dif;
        return true;
    }
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    cin >> n;
    loe(i, 1, n) cin >> a[i];
    loe(i, 1, n) cin >> b[i];
    int v;
    LL w;
    loe(i, 2, n) {
        cin >> v >> w;
        adj[v].pb(mk(i, w));
    }
    cout << (dfs(1, 0, -1) ? "YES" : "NO");
    return 0;
}


#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#define lo(i, n, m) for (int i = n; i < m; i++)
#define loe(i, n, m) for (int i = n; i <= m; i++)
#define pb push_back
#define mk make_pair
#define clr(a, b) memset((a), (b), sizeof(a))
typedef long long LL;
using namespace std;
// const int INF = 0x3f3f3f3f;
// const int INF = 0x7fffffff;
// const LL INF = 0x3f3f3f3f3f3f3f3f;
// const LL INF = 0x7fffffffffffffff;
const int NIL = -1;
template <class T>
inline T mx(T a, T b) {return a > b ? a : b;}
template <class T>
inline T mi(T a, T b) {return a < b ? a : b;}
template <class T>
inline void sw(T &a, T &b) {
    T t = a; a = b; b = t;
}
template <class T>
inline T mabs(T x) {return x < 0 ? -x : x;}
inline char gc() {
    char ret;
    while ((ret = getchar()) == ' ' || ret == '\n' || ret == '\t');
    return ret;
}

const int LIM = 1e5 + 10;
int n;
LL a[LIM], b[LIM];
typedef pair<int, LL> EDG;
vector<EDG> adj[LIM];
const LL MX = 1e18;
bool dfs(int crt, LL pre, int fa) {
    vector<EDG> &t = adj[crt];
    // cout << crt << endl;
    lo(i, 0, t.size()) if (!dfs(t[i].first, t[i].second, crt)) return false;
    if (crt == 1) return a[crt] >= b[crt];
    // if (a[crt] < 0) return false;
    if (b[crt] > a[crt]) {
        LL dif = b[crt] - a[crt];
        if (dif * pre < 0) return false;
        LL need = dif * pre;
        LL tmp = a[fa];
        a[crt] += dif, a[fa] -= need;
        if (a[fa] > tmp) return false;
        return true;
    } else if (b[crt] < a[crt]) {
        // cout << "< " << crt << " : " << a[crt] << endl;
        LL dif = a[crt] - b[crt];
        LL tmp = a[fa];
        a[crt] -= dif, a[fa] += dif;
        if (a[fa] < tmp) return false;
        return true;
    }
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    cin >> n;
    loe(i, 1, n) cin >> a[i];
    loe(i, 1, n) cin >> b[i];
    int v;
    LL w;
    loe(i, 2, n) {
        cin >> v >> w;
        adj[v].pb(mk(i, w));
    }
    cout << (dfs(1, 0, -1) ? "YES" : "NO");
    return 0;
}


#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#define lo(i, n, m) for (int i = n; i < m; i++)
#define loe(i, n, m) for (int i = n; i <= m; i++)
#define pb push_back
#define mk make_pair
#define clr(a, b) memset((a), (b), sizeof(a))
typedef long long LL;
using namespace std;
// const int INF = 0x3f3f3f3f;
// const int INF = 0x7fffffff;
// const LL INF = 0x3f3f3f3f3f3f3f3f;
// const LL INF = 0x7fffffffffffffff;
const int NIL = -1;
template <class T>
inline T mx(T a, T b) {return a > b ? a : b;}
template <class T>
inline T mi(T a, T b) {return a < b ? a : b;}
template <class T>
inline void sw(T &a, T &b) {
    T t = a; a = b; b = t;
}
template <class T>
inline T mabs(T x) {return x < 0 ? -x : x;}
inline char gc() {
    char ret;
    while ((ret = getchar()) == ' ' || ret == '\n' || ret == '\t');
    return ret;
}

const int LIM = 1e5 + 10;
int n;
LL a[LIM], b[LIM];
typedef pair<int, LL> EDG;
vector<EDG> adj[LIM];

bool dfs(int crt, LL pre, int fa) {
    vector<EDG> &t = adj[crt];
    lo(i, 0, t.size()) if (!dfs(t[i].first, t[i].second, crt)) return false;
    if (crt == 1) return a[crt] == b[crt];
    if (a[crt] < 0) return false;
    if (b[crt] > a[crt]) {
        LL dif = b[crt] - a[crt];
        if (dif * pre < 0) return false;
        LL need = dif * pre;
        a[crt] += dif, a[fa] -= need;
        return true;
    } else if (b[crt] < a[crt]) {
        LL dif = a[crt] - b[crt];
        a[crt] -= dif, a[fa] += dif;
        return true;
    }
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    cin >> n;
    loe(i, 1, n) cin >> a[i];
    loe(i, 1, n) cin >> b[i];
    int v;
    LL w;
    loe(i, 2, n) {
        cin >> v >> w;
        adj[v].pb(mk(i, w));
    }
    cout << (dfs(1, 0, -1) ? "YES" : "NO");
    return 0;
}


#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#define lo(i, n, m) for (int i = n; i < m; i++)
#define loe(i, n, m) for (int i = n; i <= m; i++)
#define pb push_back
#define mk make_pair
#define clr(a, b) memset((a), (b), sizeof(a))
typedef long long LL;
using namespace std;
// const int INF = 0x3f3f3f3f;
// const int INF = 0x7fffffff;
// const LL INF = 0x3f3f3f3f3f3f3f3f;
// const LL INF = 0x7fffffffffffffff;
const int NIL = -1;
template <class T>
inline T mx(T a, T b) {return a > b ? a : b;}
template <class T>
inline T mi(T a, T b) {return a < b ? a : b;}
template <class T>
inline void sw(T &a, T &b) {
    T t = a; a = b; b = t;
}
template <class T>
inline T mabs(T x) {return x < 0 ? -x : x;}
inline char gc() {
    char ret;
    while ((ret = getchar()) == ' ' || ret == '\n' || ret == '\t');
    return ret;
}

const int LIM = 1e5 + 10;
int n;
LL a[LIM], b[LIM];
typedef pair<int, LL> EDG;
vector<EDG> adj[LIM];

bool dfs(int crt, LL pre, int fa) {
    vector<EDG> &t = adj[crt];
    lo(i, 0, t.size()) if (!dfs(t[i].first, t[i].second, crt)) return false;
    if (crt == 1) return a[crt] == b[crt];
    if (a[crt] < 0) return false;
    if (b[crt] > a[crt]) {
        LL dif = b[crt] - a[crt];
        if (dif * pre < 0) return false;
        LL need = dif * pre;
        a[crt] += need, a[fa] -= need;
        return true;
    } else if (b[crt] < a[crt]) {
        LL dif = a[crt] - b[crt];
        a[crt] -= dif, a[fa] += dif;
        return true;
    }
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    cin >> n;
    loe(i, 1, n) cin >> a[i];
    loe(i, 1, n) cin >> b[i];
    int v;
    LL w;
    loe(i, 2, n) {
        cin >> v >> w;
        adj[v].pb(mk(i, w));
    }
    cout << (dfs(1, 0, -1) ? "YES" : "NO");
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
/*    freopen("k.in", "r", stdin);
    freopen("k.out", "w", stdout); */
// clock_t c1 = clock();
// std::cerr << "Time:" << clock() - c1 <<"ms" << std::endl;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define de(a) cout << #a << " = " << a << endl
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = n; i >= a; i--)
#define ls ((x) << 1)
#define rs ((x) << 1 | 1)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<ll, ll> PLL;
typedef vector<int, int> VII;
#define inf 0x3f3f3f3f
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll MAXN = 1e6 + 7;
const ll MAXM = 2e6 + 7;
const ll MOD = 1e9 + 7;
const double eps = 1e-6;
const double pi = acos(-1.0);
ll a[MAXN], b[MAXN];
vector<PII> vec[MAXN];
bool flag = true;
void dfs(int now)
{
    for (auto i : vec[now])
    {
        int to = i.first, k = i.second;
        dfs(to);
        if (b[to] < 0)
        {
            if (1.0 * b[to] * k + b[now] < -1e17)
                flag = false;
            b[now] += b[to] * k;
        }
        else
            b[now] += b[to];
    }
}
int main()
{
    int n;
    while (~scanf("%d", &n))
    {
        flag = true;
        for (int i = 1; i <= n; i++)
            scanf("%lld", &b[i]);
        for (int i = 1; i <= n; i++)
            scanf("%lld", &a[i]), b[i] -= a[i];
        for (int i = 1; i <= n; i++)
            vec[i].clear();
        for (int i = 2; i <= n; i++)
        {
            int x, k;
            scanf("%d%d", &x, &k);
            vec[x].push_back({i, k});
        }
        dfs(1);
        if (flag && b[1] >= 0)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}


// clang-format off
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#ifndef ritick
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#endif

// #define int long long
typedef long long ll;
typedef long double ld;
typedef long double f80;
typedef pair<int, int> pii;
typedef gp_hash_table<int, int> umap;
typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update> oset;
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<pii> vii;

#define INF 100000000000000000
#define inf 1000000000
#define MOD  998244353
// #define EPS 1e-7
#define PI 3.1415926535897932385
// #define PI acos(-1)

#define pb emplace_back
#define bitc __builtin_popcountll
#define mp make_pair
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
#define len(x) (int)x.length()

#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define foreach(it, ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fil(ar, val) memset(ar, val, sizeof(ar))  // 0x3f for inf, 0x80 for -INF can also use with pairs

#ifdef ritick
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T>
void __p(std::vector<T> a) { cout << "{ "; for (auto p : a) __p(p); cout << "}"; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.first); __p(a.second); cout << "}"; }
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) { __p(a1); __p(a...); }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cout<<name<<" : ";__p(arg1);cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    int bracket=0,i=0;
    for(; ;i++)
        if(names[i]==','&&bracket==0)
            break;
        else if(names[i]=='(')
            bracket++;
        else if(names[i]==')')
            bracket--;
    const char *comma=names+i;
    cout.write(names,comma-names)<<" : ";
    __p(arg1);
    cout<<"| ";
    __f(comma+1,args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif

mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l, r) uniform_int_distribution<int>(l, r)(rng32)
inline bool equals(double a, double b) { return fabs(a - b) < 1e-9; }
ll modpow(ll b, ll e, ll mod=MOD) {
    ll ans=1; for(;e;b=b*b%mod,e/=2) if(e&1) ans=ans*b%mod; return ans; }

ld modp(ld b, ll e) {
    ld ans=1; for(;e;b=b*b,e/=2) if(e&1) ans=ans*b; return ans; }

vector<pair<ll,ll>>v[100005];
ll b[100005];
ll a[100005];

ll dfs(ll x)
{
    ld req=b[x]-a[x];
    for(auto z:v[x])
    {
        ll bt=dfs(z.ff);
        if(bt<=0)
        {
            req+=bt*1.0*z.ss;
        }
        else
        {
            req+=bt;
        }
    }
    if(req<=-INF)
    {
        req=-INF;
    }
    return (ll)req;
}

void solve()
{
    ll n;
    cin>>n;
    rep(i,n)
    {
        cin>>b[i+1];
    }
    rep(i,n)
    {
        cin>>a[i+1];
    }
    for(ll i=2;i<=n;i++)
    {
        ll x,y;
        cin>>x>>y;
        v[x].pb(mp(i,y));
    }
    // trace(dfs(1));
    if(dfs(1)>=0)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }

}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0), cout.precision(15);   cout<<fixed;
    #ifdef ritick
        cin.exceptions(cin.failbit);
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    // cin>>t;
    fr(i,1,t)
    {
        // cout<<"Case "<<i<<": "<<endl;
        solve();
    }
    end_routine();
}


#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pib = pair<int,bool>;
using ll = long long;
using ld = long double;
#define all(x) (x).begin(),(x).end()
#ifdef fread_unlocked
#define fread fread_unlocked
#define fwrite fwrite_unlocked
#endif
#define mp make_pair
#define lc ind<<1
#define rc ind<<1|1
const int MN = 1e5+5, MK = 6e4 + 5, MOD = 1e9+7, BASE = 31, MASK = (1 << 10) - 1;
ll a[MN], b[MN],need[MN];
vector<pii> adj[MN];
ll dfs (int cur, int p = -1, int dist = 1) {
	for (pii pp : adj[cur]) if (pp.first != p) {
		ll ree = dfs(pp.first,cur,pp.second);
		if ((ld)a[cur] + ree > 1e18) {printf ("NO\n"); exit(0);}
		a[cur] += ree;
	}
	if (a[cur] >= b[cur]) {
		if ((ld)(a[cur]-b[cur]) * dist > 1e18) {printf ("NO\n"); exit(0);}
		return (a[cur] - b[cur]) * dist;
	}
	else return a[cur] - b[cur];
}
int main () {
	int n;
	scanf ("%d",&n);
	for (int i = 1; i <= n; i++) scanf ("%lld",&b[i]);
	for (int i = 1; i <= n; i++) scanf ("%lld",&a[i]);
	for (int i = 2; i <= n; i++) {
		int p,w;
		scanf ("%d %d",&p,&w);
		adj[p].emplace_back(i,w);
	}
	printf(dfs(1) > 0 ? "NO\n" : "YES\n");
	return 0;
}


#include <bits/stdc++.h>
#define double long double
#define SZ(v) ((int)v.size())
using namespace std;
typedef long long ll;

#define DEBUG(x) cerr << #x << " = " << x << '\n';

ll abc(ll x) {
	return x >= 0 ? x : -x;
}

class Task {
	public:

		vector<ll> a, b;
		vector<vector<array<int, 2>>> g;

		ll dfs(int v) {
			ll need = a[v] - b[v];
			for (auto e: g[v]) {
				int u = e[0];
				int k = e[1];
				ll need_u = dfs(u);
				if (need_u < 0) {
					if (abc(need_u) > 1e18 / k) {
						cout << "NO\n";
						exit(0);
					}
					need += need_u * k;
					if (abc(need) > 1e18) {
						cout << "NO\n";
						exit(0);
					}
				} else {
					need += need_u;
					if (abc(need) > 1e18) {
						cout << "NO\n";
						exit(0);
					}
				}
			}
			return need;
		}

		void solve() {
			int n;
			cin >> n;
			a.resize(n);
			b.resize(n);
			for (int i = 0; i < n; i++) cin >> a[i];
			for (int i = 0; i < n; i++) cin >> b[i];
			g.resize(n);
			for (int i = 1; i < n; i++) {
				int u, k;
				cin >> u >> k;
				u--;
				g[u].push_back({i, k});
			}
			ll need = dfs(0);
			if (need >= 0) {
				cout << "YES\n";
			} else {
				cout << "NO\n";
			}
		}
};

int main() {
	int T = 1;
	for (int t = 1; t <= T; t++) {
		(new Task())->solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define double long double
#define SZ(v) ((int)v.size())
using namespace std;
typedef long long ll;

#define DEBUG(x) cerr << #x << " = " << x << '\n';

class Task {
	public:

		vector<ll> a, b;
		vector<vector<array<int, 2>>> g;

		ll dfs(int v, int p = -1) {
			ll need = a[v] - b[v];
			for (auto e: g[v]) {
				int u = e[0];
				int k = e[1];
				if (u == p) continue;
				ll need_u = dfs(u, v);
				if (need_u < 0) {
					need += need_u * k;
				} else {
					need += need_u;
				}
			}
			return need;
		}

		void solve() {
			int n;
			cin >> n;
			a.resize(n);
			b.resize(n);
			for (int i = 0; i < n; i++) cin >> a[i];
			for (int i = 0; i < n; i++) cin >> b[i];
			g.resize(n);
			for (int i = 1; i < n; i++) {
				int u, k;
				cin >> u >> k;
				u--;
				g[u].push_back({i, k});
			}
			ll need = dfs(0);
			if (need >= 0) {
				cout << "YES\n";
			} else {
				cout << "NO\n";
			}
		}
};

int main() {
	int T = 1;
	for (int t = 1; t <= T; t++) {
		(new Task())->solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define double long double
#define SZ(v) ((int)v.size())
using namespace std;
typedef long long ll;

#define DEBUG(x) cerr << #x << " = " << x << '\n';

class Task {
	public:

		vector<ll> a, b;
		vector<vector<array<int, 2>>> g;

		int dfs(int v, int p = -1) {
			ll need = a[v] - b[v];
			for (auto e: g[v]) {
				int u = e[0];
				int k = e[1];
				if (u == p) continue;
				ll need_u = dfs(u, v);
				if (need_u < 0) {
					need += need_u * k;
				} else {
					need += need_u;
				}
			}
			return need;
		}

		void solve() {
			int n;
			cin >> n;
			a.resize(n);
			b.resize(n);
			for (int i = 0; i < n; i++) cin >> a[i];
			for (int i = 0; i < n; i++) cin >> b[i];
			g.resize(n);
			for (int i = 1; i < n; i++) {
				int u, k;
				cin >> u >> k;
				u--;
				g[u].push_back({i, k});
			}
			ll need = dfs(0);
			if (need >= 0) {
				cout << "YES\n";
			} else {
				cout << "NO\n";
			}
		}
};

int main() {
	int T = 1;
	for (int t = 1; t <= T; t++) {
		(new Task())->solve();
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int c=100002;
long long n, a[c], b[c], as, bs, dif, x[c], k[c], pr;
int main()
{
    cin >> n;
    for (int i=1; i<=n; i++) cin >> a[i], as+=a[i];
    for (int i=1; i<=n; i++) cin >> b[i], bs+=b[i];
    dif=as-bs;
    for (int i=2; i<=n; i++) {
        cin >> x[i] >> k[i];
    }
    if (dif<0) pr=1;
    for (int i=n; i>=2; i--) {
        long long d=(b[i]-a[i]);
        if (d<=0) {
            a[x[i]]-=d;
        } else {
            double p=log(d)+log(k[i]);
            if (p>40.0) {
                pr=1;
                break;
            }
            else {
                a[x[i]]-=d*k[i];
                dif-=(d-1)*k[i];
                if (dif<0) {
                    pr=1;
                    break;
                }
            }
        }
    }
    if (a[1]<b[1]) pr=1;
    if (pr) cout << "NO\n";
    else cout << "YES\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int c=100002;
long long n, a[c], b[c], as, bs, dif, x[c], k[c], pr;
int main()
{
    cin >> n;
    for (int i=1; i<=n; i++) cin >> a[i], as+=a[i];
    for (int i=1; i<=n; i++) cin >> b[i], bs+=b[i];
    dif=as-bs;
    for (int i=2; i<=n; i++) {
        cin >> x[i] >> k[i];
    }
    if (dif<0) pr=1;
    for (int i=n; i>=1; i--) {
        long long d=(b[i]-a[i]);
        //cout << i << " " << d << " " << x[i] << " " << k[i] << endl;
        if (d<=0) {
            a[x[i]]+=d;
        } else {
            double p=log(d)+log(k[i]);
            if (p>40.0) {
                pr=1;
                break;
            }
            else {
                a[x[i]]-=d*k[i];
                dif-=(d-1)*k[i];
                if (dif<0) {
                    pr=1;
                    break;
                }
            }
        }
    }
    if (pr) cout << "NO\n";
    else cout << "YES\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int n;
long long b[100005];
long long a[100005];
long long y[100005];
int parent[100005];
int child[100005];

int main() {
    memset(child, 0, sizeof child);
    parent[0] = 0;
    scanf("%d", &n);
    for (int i=0; i<n; i++) { scanf("%lld", &b[i]); }
    for (int i=0; i<n; i++) { scanf("%lld", &a[i]); }
    for (int i=1; i<n; i++) {
        scanf("%d%lld", &parent[i], &y[i]);
        parent[i]--; // change to zero based
        child[parent[i]]++;
    }

    queue<int> q;

    for (int i=0; i<n; i++) {
        if (child[i] == 0) {
            q.push(i); // push all leaves
        }
    }

    while (!q.empty()) {
        int top = q.front(); q.pop();

        long long x = b[top] - a[top];
        if (parent[top] != top) {
            if (x > 0) {
                b[parent[top]] += x;
            } else if (x < 0) {
                if (llabs(y[top]) > llabs(1e17 / x)) {
                    printf("NO\n");
                    return 0;
                }
                b[parent[top]] += x * y[top];
            }

            child[parent[top]]--;
            if (child[parent[top]] == 0) {
                q.push(parent[top]);
            }
        }
    }

    if (b[0] >= 0) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
}


#include <bits/stdc++.h>
using namespace std;

int n;
long long b[100005];
long long a[100005];
long long y[100005];
int parent[100005];
int child[100005];

int main() {
    memset(child, 0, sizeof child);
    parent[0] = 0;
    scanf("%d", &n);
    for (int i=0; i<n; i++) { scanf("%lld", &b[i]); }
    for (int i=0; i<n; i++) { scanf("%lld", &a[i]); }
    for (int i=1; i<n; i++) {
        scanf("%d%lld", &parent[i], &y[i]);
        parent[i]--; // change to zero based
        child[parent[i]]++;
    }

    queue<int> q;

    for (int i=0; i<n; i++) {
        if (child[i] == 0) {
            q.push(i); // push all leaves
        }
    }

    while (!q.empty()) {
        int top = q.front(); q.pop();

        long long x = b[top] - a[top];
        if (parent[top] != top) {
            if (x > 0) {
                b[parent[top]] += x;
            } else if (x < 0) {
                if (abs(y[top]) > abs(1e17 / x)) {
                    printf("NO\n");
                    return 0;
                }
                b[parent[top]] += x * y[top];
            }

            child[parent[top]]--;
            if (child[parent[top]] == 0) {
                q.push(parent[top]);
            }
        }
    }

    if (b[0] >= 0) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
}


#include <bits/stdc++.h>
using namespace std;

int n;
long double b[100005];
long double a[100005];
long double y[100005];
int parent[100005];
int child[100005];

int main() {
    memset(child, 0, sizeof child);
    parent[0] = 0;
    scanf("%d", &n);
    for (int i=0; i<n; i++) { scanf("%Lf", &b[i]); }
    for (int i=0; i<n; i++) { scanf("%Lf", &a[i]); }
    for (int i=1; i<n; i++) {
        scanf("%d%Lf", &parent[i], &y[i]);
        parent[i]--; // change to zero based
        child[parent[i]]++;
    }

    queue<int> q;

    for (int i=0; i<n; i++) {
        if (child[i] == 0) {
            q.push(i); // push all leaves
        }
    }

    while (!q.empty()) {
        int top = q.front(); q.pop();

        long double x = b[top] - a[top];
        if (parent[top] != top) {
            if (x > 0) {
                b[parent[top]] += x;
            } else if (x < 0) {
                if (llabs(y[top]) > llabs(1e17 / x)) {
                    printf("NO\n");
                    return 0;
                }
                b[parent[top]] += x * y[top];
            }

            child[parent[top]]--;
            if (child[parent[top]] == 0) {
                q.push(parent[top]);
            }
        }
    }

    if (b[0] >= 0) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
}


#include <bits/stdc++.h>
using namespace std;

int n;
__int128_t b[100005];
__int128_t a[100005];
__int128_t y[100005];
int parent[100005];
int child[100005];

int main() {
    memset(child, 0, sizeof child);
    memset(b, 0, sizeof b);
    memset(a, 0, sizeof a);
    memset(y, 0, sizeof y);
    parent[0] = 0;
    scanf("%d", &n);
    for (int i=0; i<n; i++) { scanf("%lld", &b[i]); }
    for (int i=0; i<n; i++) { scanf("%lld", &a[i]); }
    for (int i=1; i<n; i++) {
        scanf("%d%lld", &parent[i], &y[i]);
        parent[i]--; // change to zero based
        child[parent[i]]++;
    }

    queue<int> q;

    for (int i=0; i<n; i++) {
        if (child[i] == 0) {
            q.push(i); // push all leaves
        }
    }

    while (!q.empty()) {
        int top = q.front(); q.pop();

        __int128 x = b[top] - a[top];
        if (parent[top] != top) {
            if (x > 0) {
                b[parent[top]] += x;
            } else if (x < 0) {
                b[parent[top]] += x * y[top];
            }

            child[parent[top]]--;
            if (child[parent[top]] == 0) {
                q.push(parent[top]);
            }
        }
    }

    if (b[0] >= 0) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
}


#include <bits/stdc++.h>
using namespace std;

int n;
long long b[100005];
long long a[100005];
long long y[100005];
int parent[100005];
int child[100005];

int main() {
    memset(child, 0, sizeof child);
    parent[0] = 0;
    scanf("%d", &n);
    for (int i=0; i<n; i++) { scanf("%lld", &b[i]); }
    for (int i=0; i<n; i++) { scanf("%lld", &a[i]); }
    for (int i=1; i<n; i++) {
        scanf("%d%lld", &parent[i], &y[i]);
        parent[i]--; // change to zero based
        child[parent[i]]++;
    }

    queue<int> q;

    for (int i=0; i<n; i++) {
        if (child[i] == 0) {
            q.push(i); // push all leaves
        }
    }

    while (!q.empty()) {
        int top = q.front(); q.pop();

        long long x = b[top] - a[top];
        if (parent[top] != top) {
            if (x > 0) {
                b[parent[top]] += x;
            } else if (x < 0) {
                if (y[top] > 1e17 / x) {
                    printf("NO\n");
                    return 0;
                }
                b[parent[top]] += x * y[top];
            }

            child[parent[top]]--;
            if (child[parent[top]] == 0) {
                q.push(parent[top]);
            }
        }
    }

    if (b[0] >= 0) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }
}


#include <bits/stdc++.h>

using namespace std;

#define Speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 1000000007
#define fr first
#define sc second
#define pb push_back
#define PI acos(-1.0)
#define print(num,ans) cout<<setprecision(num)<<fixed<<ans

int n;
ll a[100100] , b[100100] , need[100100];
vector<vector<pair<ll,pair<ll,ll> > > >v;
pair<ll,ll> c[100100];

int main()
{
    Speed;
    cin>>n;
    v.clear();
    v.resize(n + 1);
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)cin>>b[i];
    for(int i=1;i<=n;i++)need[i] = b[i] - a[i];
    for(int i=2;i<=n;i++)
    {
        int x,k;
        cin>>x>>k;
        c[i] = {x , k};
    }
    for(int i=n;i>1;i--)
    {
        if(need[i] < 0)
        {
            need[c[i].fr] += need[i];
        }
        else if(need[i] > 0)
        {
            need[c[i].fr] += (c[i].sc * need[i]);
            if(need[c[i].fr] > 1e17)return cout<<"NO"<<endl , 0;
        }
    }
    if(need[1] <= 0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define Speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 1000000007
#define fr first
#define sc second
#define pb push_back
#define PI acos(-1.0)
#define print(num,ans) cout<<setprecision(num)<<fixed<<ans

int n;
ll a[100100] , b[100100] , need[100100];
pair<ll,ll> c[100100];

int main()
{
    Speed;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)cin>>b[i];
    for(int i=1;i<=n;i++)need[i] = b[i] - a[i];
    for(int i=2;i<=n;i++)
    {
        int x,k;
        cin>>x>>k;
        c[i] = {x , k};
    }
    for(int i=n;i>1;i--)
    {
        if(need[i] < 0) need[c[i].fr] += need[i];
        else if(need[i] > 0)
        {
            if(log10(c[i].sc) + log10(need[i]) > 17)return cout<<"NO"<<endl , 0;
            need[c[i].fr] += (c[i].sc * need[i]);
            if(need[c[i].fr] > 1e17)return cout<<"NO"<<endl , 0;
        }
    }
    if(need[1] <= 0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define Speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 1000000007
#define fr first
#define sc second
#define pb push_back
#define PI acos(-1.0)
#define print(num,ans) cout<<setprecision(num)<<fixed<<ans

int n;
ll a[100100] , b[100100] , need[100100];
vector<vector<pair<ll,pair<ll,ll> > > >v;
pair<ll,ll> c[100100];

int main()
{
    Speed;
    cin>>n;
    v.clear();
    v.resize(n + 1);
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)cin>>b[i];
    for(int i=1;i<=n;i++)need[i] = b[i] - a[i];
    for(int i=2;i<=n;i++)
    {
        int x,k;
        cin>>x>>k;
        c[i] = {x , k};
    }
    for(int i=n;i>=1;i--)
    {
        if(need[i] < 0)
        {
            need[c[i].fr] += abs(need[i]);
        }
        else if(need[i] > 0)
        {
            need[c[i].fr] -= (c[i].sc * need[i]);
            if(need[c[i].fr] < -1e17)return cout<<"NO"<<endl , 0;
        }
    }
    if(need[1] >= b[1])cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define Speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 1000000007
#define fr first
#define sc second
#define pb push_back
#define PI acos(-1.0)
#define print(num,ans) cout<<setprecision(num)<<fixed<<ans

int n;
ll a[100100] , b[100100] , need[100100];
vector<vector<pair<ll,pair<ll,ll> > > >v;
pair<ll,ll> c[100100];

int main()
{
    Speed;
    cin>>n;
    v.clear();
    v.resize(n + 1);
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)cin>>b[i];
    for(int i=1;i<=n;i++)need[i] = b[i] - a[i];
    for(int i=2;i<=n;i++)
    {
        int x,k;
        cin>>x>>k;
        c[i] = {x , k};
    }
    for(int i=n;i>=1;i--)
    {
        if(need[i] < 0)
        {
            need[c[i].fr] += abs(need[i]);
        }
        else if(need[i] > 0)
        {
            need[c[i].fr] -= (c[i].sc * need[i]);
        //    if(need[c[i].fr] < -1e17)return cout<<"NO"<<endl , 0;
        }
    }
    if(need[1] >= b[1])cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define Speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 1000000007
#define fr first
#define sc second
#define pb push_back
#define PI acos(-1.0)
#define print(num,ans) cout<<setprecision(num)<<fixed<<ans

int n;
ll a[100100] , b[100100] , need[100100];
pair<ll,ll> c[100100];

int main()
{
    Speed;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)cin>>b[i];
    for(int i=1;i<=n;i++)need[i] = b[i] - a[i];
    for(int i=2;i<=n;i++)
    {
        int x,k;
        cin>>x>>k;
        c[i] = {x , k};
    }
    for(int i=n;i>1;i--)
    {
        if(need[i] < 0) need[c[i].fr] += need[i];
        else if(need[i] > 0)
        {
            if(log10(c[i].sc) + log10(need[i]) > 17)return cout<<"NO"<<endl , 0;
            need[c[i].fr] += (c[i].sc * need[i]);
        //    if(need[c[i].fr] > 1e17)return cout<<"NO"<<endl , 0;
        }
    }
    if(need[1] <= 0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
////
//    #pragma GCC optimize("unroll-loops")
//    #pragma GCC optimize("Ofast")
//    #pragma GCC optimize("-O3")
//    #pragma GCC optimize("no-stack-protector")
//    #pragma GCC optimize("fast-math")
//////#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cout << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cout << endl; }
eni(!=) cout << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fi first
#define f first
#define se second
#define s second
#define vi_a vector<int>a;
#define p_b push_back
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ll long long
//#define ull unsigned long long
typedef unsigned long long ull;
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(),x.end()
#define getfiles    ifstream cin("input.txt");ofstream cout("output.txt");
#define pw(x) (1ll << x)
#define sz(x) (ll)x.size()
#define endl "\n"
#define rall(x) x.rbegin(),x.rend()
#define len(a) (ll)a.size()
#define rep(x,l,r) for(ll x=l;x<r;x++)

//using namespace __gnu_pbds;
ld eps = (ld)1 / 1e6;
const ld pi=3.14159265359;
ll inf = 1e18,mod1=1e9+7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
void binary(ll val,int to) {for(int i=0;i<to;i++) cerr<<(pw(i) & val ? 1 : 0); cerr<<endl;}
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const ll R=1e4;
const ll tx[4]={1,0,-1,0};
const ll ty[4]={0,1,0,-1};
const char rev_to[4]={'E','W','N','S'};
const int N=1e5+1;
const int M=1e9+1;
//typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> st;
void bad(){
    cout<<"NO";
    exit(0);
}
vector<pii>g[N];
ll a[N],b[N];
int n;
int p[N];
/// надо,имеется
void dfs(int v,int p,ll rb){
    ll need=0;
    for(auto &z : g[v]){
        if(z.f==p) continue;
        dfs(z.f,v,z.s);
    }
    if(a[v]<b[v]){
        if(v^p)b[p]+=b[v]-a[v];
    }else{
        if(v^p)a[p]+=(ld)(a[v]-b[v])*1ll*rb;
    }
}
signed main()
{
    fast_io;
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
    cin>>n;
    fill(p,p+N,-1);
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;--x;
        g[x].p_b({i,y});
        p[i]=x;
    }
    for(int i=0;i<n;i++){
        if(p[i]==-1){
            dfs(i,i,-1);
        }
    }
    for(int i=0;i<n;i++){
        if(b[i]<a[i]) bad();
    }
    cout<<"YES";
    return 0;
}
/*
1
4 3
2 4
2 5
7 3

*/


#include<bits/stdc++.h>
using namespace std;
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
////
//    #pragma GCC optimize("unroll-loops")
//    #pragma GCC optimize("Ofast")
//    #pragma GCC optimize("-O3")
//    #pragma GCC optimize("no-stack-protector")
//    #pragma GCC optimize("fast-math")
//////#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cout << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cout << endl; }
eni(!=) cout << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fi first
#define f first
#define se second
#define s second
#define vi_a vector<int>a;
#define p_b push_back
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ll long long
//#define ull unsigned long long
typedef unsigned long long ull;
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(),x.end()
#define getfiles    ifstream cin("input.txt");ofstream cout("output.txt");
#define pw(x) (1ll << x)
#define sz(x) (ll)x.size()
#define endl "\n"
#define rall(x) x.rbegin(),x.rend()
#define len(a) (ll)a.size()
#define rep(x,l,r) for(ll x=l;x<r;x++)

//using namespace __gnu_pbds;
ld eps = (ld)1 / 1e6;
const ld pi=3.14159265359;
ll inf = 1e18,mod1=1e9+7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
void binary(ll val,int to) {for(int i=0;i<to;i++) cerr<<(pw(i) & val ? 1 : 0); cerr<<endl;}
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const ll R=1e4;
const ll tx[4]={1,0,-1,0};
const ll ty[4]={0,1,0,-1};
const char rev_to[4]={'E','W','N','S'};
const int N=1e5+1;
const int M=1e9+1;
//typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> st;
void bad(){
    cout<<"NO";
    exit(0);
}
vector<pii>g[N];
ll a[N],b[N];
int n;
int p[N];
/// надо,имеется
void dfs(int v,int p,ll rb){
    ll need=0;
    for(auto &z : g[v]){
        if(z.f==p) continue;
        dfs(z.f,v,z.s);
    }
    if(a[v]<b[v]){
        if(v^p)b[p]+=(b[v]-a[v])*1ll*rb;
    }else{
        if(v^p)a[p]+=(a[v]-b[v])*1ll*rb;
    }
    debug()<<imie(v)<<imie(a[v])<<imie(b[v]);
}
signed main()
{
    fast_io;
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
    cin>>n;
    fill(p,p+N,-1);
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;--x;
        g[x].p_b({i,y});
        p[i]=x;
    }
    for(int i=0;i<n;i++){
        if(p[i]==-1){
            dfs(i,i,-1);
        }
    }
    for(int i=0;i<n;i++){
        if(b[i]<a[i]) bad();
    }
    cout<<"YES";
    return 0;
}
/*
1
4 3
2 4
2 5
7 3

*/


/*
   О НЕТ! ОНИ ДОГОНЯЮТ!!!
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
   🐹🐹🐹🐹🐹🐹🐹🐹🐹🐹
*/

#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

const int N = 1e5 + 1;

vector <int> g[N];

ll b[N], a[N];
int k[N];

void dfs(int v, int pr)
{
    for (int to : g[v])
    {
        if (to != pr)
        {
            dfs(to, v);
        }
    }
    if (b[v] < a[v])
    {
        if (pr == -1)
        {
            puts("NO");
            exit(0);
        }
        ll now = (a[v] - b[v]) * k[v];
        if (now / k[v] != (a[v] - b[v]) || now / (a[v] - b[v]) != k[v] || now < max(a[v] - b[v], (ll) k[v]))
        {
            puts("NO");
            exit(0);
        }
        ll was = a[pr];
        a[pr] += now;
        if (a[pr] - now != was || a[pr] - was != now || a[pr] <= 0)
        {
            puts("NO");
            exit(0);
        }
    }
    else
    {
        if (pr != -1)
        {
            b[pr] += b[v];
            ll was = a[pr];
            a[pr] += a[v];
            if (a[pr] - a[v] != was || a[pr] - was != a[v] || a[pr] <= 0)
            {
                puts("NO");
                exit(0);
            }
        }
    }
    cout<<v<<' '<<a[v]<<' '<<b[v]<<endl;
}

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%lld", &b[i]);
    for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
    for (int i = 1; i < n; i++)
    {
        int x;
        scanf("%d%d", &x, &k[i]);
        x--;
        g[x].push_back(i);
    }
    dfs(0, -1);
    puts("YES");
}


#include<bits/stdc++.h>
using namespace std;
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
////
//    #pragma GCC optimize("unroll-loops")
//    #pragma GCC optimize("Ofast")
//    #pragma GCC optimize("-O3")
//    #pragma GCC optimize("no-stack-protector")
//    #pragma GCC optimize("fast-math")
//////#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cout << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cout << endl; }
eni(!=) cout << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fi first
#define f first
#define se second
#define s second
#define vi_a vector<int>a;
#define p_b push_back
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ll long long
//#define ull unsigned long long
typedef unsigned long long ull;
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(),x.end()
#define getfiles    ifstream cin("input.txt");ofstream cout("output.txt");
#define pw(x) (1ll << x)
#define sz(x) (ll)x.size()
#define endl "\n"
#define rall(x) x.rbegin(),x.rend()
#define len(a) (ll)a.size()
#define rep(x,l,r) for(ll x=l;x<r;x++)

//using namespace __gnu_pbds;
ld eps = (ld)1 / 1e6;
const ld pi=3.14159265359;
ll inf = 1e18,mod1=1e9+7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
void binary(ll val,int to) {for(int i=0;i<to;i++) cerr<<(pw(i) & val ? 1 : 0); cerr<<endl;}
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const ll R=1e4;
const ll tx[4]={1,0,-1,0};
const ll ty[4]={0,1,0,-1};
const char rev_to[4]={'E','W','N','S'};
const int N=1e5+1;
const int M=1e9+1;
//typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> st;
void bad(){
    cout<<"NO";
    exit(0);
}
vector<pii>g[N];
ll a[N],b[N];
int n;
int p[N];
/// надо,имеется
void dfs(int v,int p,ll rb){
    ll need=0;
    for(auto &z : g[v]){
        if(z.f==p) continue;
        dfs(z.f,v,z.s);
    }
    if(a[v]<b[v]){
        if(v^p)b[p]+=(b[v]-a[v])*1ll*rb;
    }else{
        if(v^p)a[p]+=(a[v]-b[v])*1ll*rb;
    }
    ///debug()<<imie(v)<<imie(a[v])<<imie(b[v]);
}
signed main()
{
    fast_io;
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
    cin>>n;
    fill(p,p+N,-1);
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;--x;
        g[x].p_b({i,y});
        p[i]=x;
    }
    for(int i=0;i<n;i++){
        if(p[i]==-1){
            dfs(i,i,-1);
        }
    }
    for(int i=0;i<n;i++){
        if(b[i]<a[i]) bad();
    }
    cout<<"YES";
    return 0;
}
/*
1
4 3
2 4
2 5
7 3

*/


#include<bits/stdc++.h>
using namespace std;
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
////
//    #pragma GCC optimize("unroll-loops")
//    #pragma GCC optimize("Ofast")
//    #pragma GCC optimize("-O3")
//    #pragma GCC optimize("no-stack-protector")
//    #pragma GCC optimize("fast-math")
//////#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cout << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cout << endl; }
eni(!=) cout << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fi first
#define f first
#define se second
#define s second
#define vi_a vector<int>a;
#define p_b push_back
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ll long long
//#define ull unsigned long long
typedef unsigned long long ull;
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(),x.end()
#define getfiles    ifstream cin("input.txt");ofstream cout("output.txt");
#define pw(x) (1ll << x)
#define sz(x) (ll)x.size()
#define endl "\n"
#define rall(x) x.rbegin(),x.rend()
#define len(a) (ll)a.size()
#define rep(x,l,r) for(ll x=l;x<r;x++)

//using namespace __gnu_pbds;
ld eps = (ld)1 / 1e6;
const ld pi=3.14159265359;
ll inf = 1e18,mod1=1e9+7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
void binary(ll val,int to) {for(int i=0;i<to;i++) cerr<<(pw(i) & val ? 1 : 0); cerr<<endl;}
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const ll R=1e4;
const ll tx[4]={1,0,-1,0};
const ll ty[4]={0,1,0,-1};
const char rev_to[4]={'E','W','N','S'};
const int N=1e5+1;
const int M=1e9+1;
//typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> st;
void bad(){
    cout<<"NO";
    exit(0);
}
vector<pii>g[N];
ll a[N],b[N];
int n;
int p[N];
/// надо,имеется
void dfs(int v,int p,ll rb){
    ll need=0;
    for(auto &z : g[v]){
        if(z.f==p) continue;
        dfs(z.f,v,z.s);
    }
    if(a[v]<b[v]){
        if(v^p)b[p]+=b[v]-a[v];
    }else{
        if(v^p)b[p]-=ceil((ld)(a[v]-b[v])/rb)*1ll*rb;
    }
}
signed main()
{
    fast_io;
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
    cin>>n;
    fill(p,p+N,-1);
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;--x;
        g[x].p_b({i,y});
        p[i]=x;
    }
    for(int i=0;i<n;i++){
        if(p[i]==-1){
            dfs(i,i,-1);
        }
    }
    for(int i=0;i<n;i++){
        if(b[i]<a[i]) bad();
    }
    cout<<"YES";
    return 0;
}
/*
1
4 3
2 4
2 5
7 3

*/


#include<bits/stdc++.h>
using namespace std;
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
////
//    #pragma GCC optimize("unroll-loops")
//    #pragma GCC optimize("Ofast")
//    #pragma GCC optimize("-O3")
//    #pragma GCC optimize("no-stack-protector")
//    #pragma GCC optimize("fast-math")
//////#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cout << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cout << endl; }
eni(!=) cout << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fi first
#define f first
#define se second
#define s second
#define vi_a vector<int>a;
#define p_b push_back
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ll long long
//#define ull unsigned long long
typedef unsigned long long ull;
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(),x.end()
#define getfiles    ifstream cin("input.txt");ofstream cout("output.txt");
#define pw(x) (1ll << x)
#define sz(x) (ll)x.size()
#define endl "\n"
#define rall(x) x.rbegin(),x.rend()
#define len(a) (ll)a.size()
#define rep(x,l,r) for(ll x=l;x<r;x++)

//using namespace __gnu_pbds;
ld eps = (ld)1 / 1e6;
const ld pi=3.14159265359;
ll inf = 1e18,mod1=1e9+7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
void binary(ll val,int to) {for(int i=0;i<to;i++) cerr<<(pw(i) & val ? 1 : 0); cerr<<endl;}
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const ll R=1e4;
const ll tx[4]={1,0,-1,0};
const ll ty[4]={0,1,0,-1};
const char rev_to[4]={'E','W','N','S'};
const int N=1e5+1;
const int M=1e9+1;
//typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> st;
void bad(){
    cout<<"NO";
    exit(0);
}
vector<pii>g[N];
ll a[N],b[N];
int n;
int p[N];
/// надо,имеется
void dfs(int v,int p,ll rb){
    ll need=0;
    for(auto &z : g[v]){
        if(z.f==p) continue;
        dfs(z.f,v,z.s);
    }
    if(a[v]<b[v]){
        if(v^p)b[p]+=b[v]-a[v];
    }else{
        if(v^p)a[p]+=ceil((ld)(a[v]-b[v])/rb)*1ll*rb;
    }
}
signed main()
{
    fast_io;
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
    cin>>n;
    fill(p,p+N,-1);
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;--x;
        g[x].p_b({i,y});
        p[i]=x;
    }
    for(int i=0;i<n;i++){
        if(p[i]==-1){
            dfs(i,i,-1);
        }
    }
    for(int i=0;i<n;i++){
        if(b[i]<a[i]) bad();
    }
    cout<<"YES";
    return 0;
}
/*
1
4 3
2 4
2 5
7 3

*/


#include<bits/stdc++.h>
using namespace std;
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
////
//    #pragma GCC optimize("unroll-loops")
//    #pragma GCC optimize("Ofast")
//    #pragma GCC optimize("-O3")
//    #pragma GCC optimize("no-stack-protector")
//    #pragma GCC optimize("fast-math")
//////#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cout << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cout << endl; }
eni(!=) cout << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fi first
#define f first
#define se second
#define s second
#define vi_a vector<int>a;
#define p_b push_back
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ll long long
//#define ull unsigned long long
typedef unsigned long long ull;
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(),x.end()
#define getfiles    ifstream cin("input.txt");ofstream cout("output.txt");
#define pw(x) (1ll << x)
#define sz(x) (ll)x.size()
#define endl "\n"
#define rall(x) x.rbegin(),x.rend()
#define len(a) (ll)a.size()
#define rep(x,l,r) for(ll x=l;x<r;x++)

//using namespace __gnu_pbds;
ld eps = (ld)1 / 1e6;
const ld pi=3.14159265359;
ll inf = 1e16+2,mod1=1e9+7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
void binary(ll val,int to) {for(int i=0;i<to;i++) cerr<<(pw(i) & val ? 1 : 0); cerr<<endl;}
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const ll R=1e4;
const ll tx[4]={1,0,-1,0};
const ll ty[4]={0,1,0,-1};
const char rev_to[4]={'E','W','N','S'};
const int N=1e5+1;
const int M=1e9+1;
//typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> st;
void bad(){
    cout<<"NO";
    exit(0);
}
vector<pii>g[N];
ll a[N],b[N];
int n;
int p[N];
/// надо,имеется
ll dfs(int v,int p){
    ll need=0;
    for(auto &z : g[v]){
        if(z.f==p) continue;
        ll tmp=dfs(z.f,v);
        if(tmp<0){
            if(abs(tmp)>=ceil((ld)inf/z.s)){
                bad();
            }
            need+=tmp*1ll*z.s;
        }else{
            need+=tmp;
        }
    }
    need+=b[v]-a[v];
    return need;
}
signed main()
{
    fast_io;
    cin>>n;
    fill(p,p+N,-1);
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;--x;
        g[x].p_b({i,y});
        p[i]=x;
    }
    for(int i=0;i<n;i++){
        if(p[i]==-1){
            if(dfs(i,i)<0)bad();
        }
    }
    cout<<"YES";
    return 0;
}
/*
1
4 3
2 4
2 5
7 3

*/


#include<bits/stdc++.h>
using namespace std;
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
////
//    #pragma GCC optimize("unroll-loops")
//    #pragma GCC optimize("Ofast")
//    #pragma GCC optimize("-O3")
//    #pragma GCC optimize("no-stack-protector")
//    #pragma GCC optimize("fast-math")
//////#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cout << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cout << endl; }
eni(!=) cout << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fi first
#define f first
#define se second
#define s second
#define vi_a vector<int>a;
#define p_b push_back
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ll long long
//#define ull unsigned long long
typedef unsigned long long ull;
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(),x.end()
#define getfiles    ifstream cin("input.txt");ofstream cout("output.txt");
#define pw(x) (1ll << x)
#define sz(x) (ll)x.size()
#define endl "\n"
#define rall(x) x.rbegin(),x.rend()
#define len(a) (ll)a.size()
#define rep(x,l,r) for(ll x=l;x<r;x++)

//using namespace __gnu_pbds;
ld eps = (ld)1 / 1e6;
const ld pi=3.14159265359;
ll inf = 1e18,mod1=1e9+7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
void binary(ll val,int to) {for(int i=0;i<to;i++) cerr<<(pw(i) & val ? 1 : 0); cerr<<endl;}
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const ll R=1e4;
const ll tx[4]={1,0,-1,0};
const ll ty[4]={0,1,0,-1};
const char rev_to[4]={'E','W','N','S'};
const int N=1e5+1;
const int M=1e9+1;
//typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> st;
void bad(){
    cout<<"NO";
    exit(0);
}
vector<pii>g[N];
ll a[N],b[N];
int n;
int p[N];
/// надо,имеется
void dfs(int v,int p,ll rb){
    ll need=0;
    for(auto &z : g[v]){
        if(z.f==p) continue;
        dfs(z.f,v,z.s);
    }
    if(a[v]<b[v]){
        if(v^p)b[p]+=(b[v]-a[v])*rb;
    }else{
        if(v^p)a[p]+=(a[v]-b[v])*1ll*rb;
    }
///    debug()<<imie(v)<<imie(a[v])<<imie(b[v]);
}
signed main()
{
    fast_io;
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
    cin>>n;
    fill(p,p+N,-1);
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;--x;
        g[x].p_b({i,y});
        p[i]=x;
    }
    for(int i=0;i<n;i++){
        if(p[i]==-1){
            dfs(i,i,-1);
        }
    }
    for(int i=0;i<n;i++){
        if(b[i]<a[i]) bad();
    }
    cout<<"YES";
    return 0;
}
/*
1
4 3
2 4
2 5
7 3

*/


#include<bits/stdc++.h>
using namespace std;
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
////
//    #pragma GCC optimize("unroll-loops")
//    #pragma GCC optimize("Ofast")
//    #pragma GCC optimize("-O3")
//    #pragma GCC optimize("no-stack-protector")
//    #pragma GCC optimize("fast-math")
//////#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cout << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cout << endl; }
eni(!=) cout << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fi first
#define f first
#define se second
#define s second
#define vi_a vector<int>a;
#define p_b push_back
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ll long long
//#define ull unsigned long long
typedef unsigned long long ull;
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(),x.end()
#define getfiles    ifstream cin("input.txt");ofstream cout("output.txt");
#define pw(x) (1ll << x)
#define sz(x) (ll)x.size()
#define endl "\n"
#define rall(x) x.rbegin(),x.rend()
#define len(a) (ll)a.size()
#define rep(x,l,r) for(ll x=l;x<r;x++)

//using namespace __gnu_pbds;
ld eps = (ld)1 / 1e6;
const ld pi=3.14159265359;
ll inf = 1e18,mod1=1e9+7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
void binary(ll val,int to) {for(int i=0;i<to;i++) cerr<<(pw(i) & val ? 1 : 0); cerr<<endl;}
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const ll R=1e4;
const ll tx[4]={1,0,-1,0};
const ll ty[4]={0,1,0,-1};
const char rev_to[4]={'E','W','N','S'};
const int N=1e5+1;
const int M=1e9+1;
//typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> st;
void bad(){
    cout<<"NO";
    exit(0);
}
vector<pii>g[N];
ll a[N],b[N];
int n;
int p[N];
/// надо,имеется
ll dfs(int v,int p){
    ll need=0;
    for(auto &z : g[v]){
        if(z.f==p) continue;
        ll tmp=dfs(z.f,v);
        if(tmp<0){
            if(tmp>=inf/z.s){
                bad();
            }
            need+=tmp*1ll*z.s;
        }else{
            need+=tmp;
        }
    }
    need+=b[v]-a[v];
    return need;
}
signed main()
{
    fast_io;
    cin>>n;
    fill(p,p+N,-1);
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;--x;
        g[x].p_b({i,y});
        p[i]=x;
    }
    for(int i=0;i<n;i++){
        if(p[i]==-1){
            if(dfs(i,i)<0)bad();
        }
    }
    cout<<"YES";
    return 0;
}
/*
1
4 3
2 4
2 5
7 3

*/


#include<bits/stdc++.h>
using namespace std;
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
////
//    #pragma GCC optimize("unroll-loops")
//    #pragma GCC optimize("Ofast")
//    #pragma GCC optimize("-O3")
//    #pragma GCC optimize("no-stack-protector")
//    #pragma GCC optimize("fast-math")
//////#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cout << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cout << endl; }
eni(!=) cout << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fi first
#define f first
#define se second
#define s second
#define vi_a vector<int>a;
#define p_b push_back
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ll long long
//#define ull unsigned long long
typedef unsigned long long ull;
////////////////////////////////???????????????CHECK THIS OUT???????????????//////////////////////////////
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(),x.end()
#define getfiles    ifstream cin("input.txt");ofstream cout("output.txt");
#define pw(x) (1ll << x)
#define sz(x) (ll)x.size()
#define endl "\n"
#define rall(x) x.rbegin(),x.rend()
#define len(a) (ll)a.size()
#define rep(x,l,r) for(ll x=l;x<r;x++)

//using namespace __gnu_pbds;
ld eps = (ld)1 / 1e6;
const ld pi=3.14159265359;
ll inf = 1e18,mod1=1e9+7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
void binary(ll val,int to) {for(int i=0;i<to;i++) cerr<<(pw(i) & val ? 1 : 0); cerr<<endl;}
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const ll R=1e4;
const ll tx[4]={1,0,-1,0};
const ll ty[4]={0,1,0,-1};
const char rev_to[4]={'E','W','N','S'};
const int N=1e5+1;
const int M=1e9+1;
//typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> st;
void bad(){
    cout<<"NO";
    exit(0);
}
vector<pii>g[N];
ll a[N],b[N];
int n;
int p[N];
/// надо,имеется
ll dfs(int v,int p){
    ll need=0;
    for(auto &z : g[v]){
        if(z.f==p) continue;
        ll tmp=dfs(z.f,v);
        if(tmp<0){
            if(abs(tmp)>=inf/z.s){
                bad();
            }
            need+=tmp*1ll*z.s;
        }else{
            need+=tmp;
        }
    }
    need+=b[v]-a[v];
    return need;
}
signed main()
{
    fast_io;
    cin>>n;
    fill(p,p+N,-1);
    for(int i=0;i<n;i++) cin>>b[i];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;--x;
        g[x].p_b({i,y});
        p[i]=x;
    }
    for(int i=0;i<n;i++){
        if(p[i]==-1){
            if(dfs(i,i)<0)bad();
        }
    }
    cout<<"YES";
    return 0;
}
/*
1
4 3
2 4
2 5
7 3

*/


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;

#define rep(i,N) for(int i=0;i<(int)(N);++i)
#define rrep(i,N) for(int i=(int)(N)-1;i>=0;--i)
#define debug(x) cout<<#x<<"="<<x<<endl;
constexpr int MOD=1000000007;
constexpr ll INF=(1LL<<61)-1;
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end
vector<int> G[100100];
vector<ll> A,B,K;
ll dfs(int i){
    ll now=0;
    for(int &e:G[i]){
        now+=dfs(e);
        if(now>2e17)fail("NO");
    }
    now+=B[i]-A[i];
    if(now>=0)return now;
    if(abs((double)now*K[i])>2e17)fail("NO");
    return now*K[i];
}
void solve(){
    int N;cin>>N;
    A.resize(N);B.resize(N);K.resize(N);
    rep(i,N)cin>>B[i];
    rep(i,N)cin>>A[i];
    K[0]=1;
    rep(i,N-1){
        int x;cin>>x>>K[i+1];x--;
        G[x].push_back(i+1);
    }
    ll res=dfs(0);
    if(res>=0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;

#define rep(i,N) for(int i=0;i<(int)(N);++i)
#define rrep(i,N) for(int i=(int)(N)-1;i>=0;--i)
#define debug(x) cout<<#x<<"="<<x<<endl;
constexpr int MOD=1000000007;
constexpr ll INF=(1LL<<61)-1;
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end
vector<int> G[100100];
vector<ll> A,B,K;
ll dfs(int i){
    ll now=0;
    for(int &e:G[i]){
        now+=dfs(e);
    }
    now+=B[i]-A[i];
    if(now>=0)return now;
    if((double)now*K[i]>2e17)fail("NO");
    return now*K[i];
}
void solve(){
    int N;cin>>N;
    A.resize(N);B.resize(N);K.resize(N);
    rep(i,N)cin>>B[i];
    rep(i,N)cin>>A[i];
    K[0]=1;
    rep(i,N-1){
        int x;cin>>x>>K[i+1];x--;
        G[x].push_back(i+1);
    }
    ll res=dfs(0);
    if(res>=0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;

#define rep(i,N) for(int i=0;i<(int)(N);++i)
#define rrep(i,N) for(int i=(int)(N)-1;i>=0;--i)
#define debug(x) cout<<#x<<"="<<x<<endl;
constexpr int MOD=1000000007;
constexpr ll INF=(1LL<<61)-1;
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end
vector<int> G[100100];
vector<ll> A,B,K;
ll dfs(int i){
    ll now=0;
    for(int &e:G[i]){
        now+=dfs(e);
    }
    now+=B[i]-A[i];
    if(now>=0)return now;
    if(abs((double)now*K[i])>2e17)fail("NO");
    return now*K[i];
}
void solve(){
    int N;cin>>N;
    A.resize(N);B.resize(N);K.resize(N);
    rep(i,N)cin>>B[i];
    rep(i,N)cin>>A[i];
    K[0]=1;
    rep(i,N-1){
        int x;cin>>x>>K[i+1];x--;
        G[x].push_back(i+1);
    }
    ll res=dfs(0);
    if(res>=0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;

#define rep(i,N) for(int i=0;i<(int)(N);++i)
#define rrep(i,N) for(int i=(int)(N)-1;i>=0;--i)
#define debug(x) cout<<#x<<"="<<x<<endl;
constexpr int MOD=1000000007;
constexpr ll INF=(1LL<<61)-1;
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> void fail(T v){cout << v << endl;exit(0);}
//template end
vector<int> G[100100];
vector<ll> A,B,K;
ll dfs(int i){
    ll now=0;
    for(int &e:G[i]){
        now+=dfs(e);
    }
    if(now>=0)return now;
    if((double)now*K[i]>2e17)fail("NO");
    return now*K[i];
}
void solve(){
    int N;cin>>N;
    A.resize(N);B.resize(N);K.resize(N);
    rep(i,N)cin>>B[i];
    rep(i,N)cin>>A[i];
    K[0]=1;
    rep(i,N-1){
        int x;cin>>x>>K[i+1];x--;
        G[x].push_back(i+1);
    }
    ll res=dfs(0);
    if(res>=0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define sc(x)            scanf("%d",&x)
#define scc(x)           scanf("%c",&x)
#define scl(x)           scanf("%lld",&x)
#define sz(v)	     	(v.size())
#define mem(v, d)		memset(v, d, sizeof(v))
#define oo				2000000100
#define OO				4000000000000000100
#define PI 3.14159265
#define S second
#define F first
typedef unsigned int uint;
typedef long long ll;
//-----------------------------------------------------
const int N = 100100;
const ll MOD = 1000000007;
const double EBS = 1e-7;

int dX[] = {0,0,1,-1};
int dY[] = {1,-1,0,0};

//int GCD(ll num,ll ones) { return !ones ? num : GCD(ones,num%ones); }
//ll lcm(ll a, ll b) { return (a / GCD(a, b)) * b; }
//double Len(ll x,ll y,ll X,ll Y) { return sqrt((X-x)*(X-x)+(Y-y)*(Y-y)); }
/*ll fastP(ll b,ll p)
{
    if(p==0) return 1;
    else if(p==1) return b;
    ll a = fastP(b,p/2);
    if(p%2) return (((a*a))*b);
    else return (a*a);
}*/
//----------------- ------   -------
int n; vector< pair<ll,ll> >adj[N]; ll a[N],b[N]; bool f = 1;
bool ok(ll x,ll y)
{
    x = log10(x); y = log10(y);
    return x+y<=18;
}
ll dfs(int cur)
{
    for(auto x:adj[cur])
        b[cur]+=dfs(x.first);

    for(auto x:adj[cur])
        if(b[x.first]<a[x.first])
            f&=ok(a[x.first]-b[x.first],x.second),b[cur]-=(a[x.first]-b[x.first])*x.second,a[x.first]=b[x.first],f&=(b[cur]<=(ll)1e18);

    ll cnt = 0;
    if(b[cur]>a[cur]) cnt = b[cur]-a[cur],a[cur]=b[cur];
    return cnt;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("i.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    sc(n);
    for(int i=0;i<n;++i)
        scl(b[i]);
    for(int i=0;i<n;++i)
        scl(a[i]);
    for(int i=1;i<n;++i)
    {
        int x,y; sc(x); sc(y);
        adj[--x].push_back({i,y});
    }
    dfs(0);
    if(b[0]>=a[0]&&f) puts("YES");
    else puts("NO");

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define sc(x)            scanf("%d",&x)
#define scc(x)           scanf("%c",&x)
#define scl(x)           scanf("%lld",&x)
#define sz(v)	     	(v.size())
#define mem(v, d)		memset(v, d, sizeof(v))
#define oo				2000000100
#define OO				4000000000000000100
#define PI 3.14159265
#define S second
#define F first
typedef unsigned int uint;
typedef long long ll;
//-----------------------------------------------------
const int N = 100100;
const ll MOD = 1000000007;
const double EBS = 1e-7;

int dX[] = {0,0,1,-1};
int dY[] = {1,-1,0,0};

//int GCD(ll num,ll ones) { return !ones ? num : GCD(ones,num%ones); }
//ll lcm(ll a, ll b) { return (a / GCD(a, b)) * b; }
//double Len(ll x,ll y,ll X,ll Y) { return sqrt((X-x)*(X-x)+(Y-y)*(Y-y)); }
/*ll fastP(ll b,ll p)
{
    if(p==0) return 1;
    else if(p==1) return b;
    ll a = fastP(b,p/2);
    if(p%2) return (((a*a))*b);
    else return (a*a);
}*/
//----------------- ------   -------
int n; vector< pair<ll,ll> >adj[N]; ll a[N],b[N];
ll dfs(int cur)
{
    for(auto x:adj[cur])
        b[cur]+=dfs(x.first);

    for(auto x:adj[cur])
        if(b[x.first]<a[x.first])
            b[cur]-=(a[x.first]-b[x.first])*x.second,a[x.first]=b[x.first];

    ll cnt = 0;
    if(b[cur]>a[cur]) cnt = b[cur]-a[cur],a[cur]=b[cur];
    return cnt;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("i.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    sc(n);
    for(int i=0;i<n;++i)
        scl(b[i]);
    for(int i=0;i<n;++i)
        scl(a[i]);
    for(int i=1;i<n;++i)
    {
        int x,y; sc(x); sc(y);
        adj[--x].push_back({i,y});
    }
    dfs(0);
    if(b[0]>=a[0]) puts("YES");
    else puts("NO");

    return 0;
}