/*
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 1e5+10;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define int ll
#define pb push_back
#define endl '\n'
//#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n;

struct node{
    int par;
    vector < int > ch;
    int zarib; //zaribe inke babash befreste be in
    int val , target;
}m[maxn];

void dokme(){
    cout << "NO";
    exit(0);
}

void dfs(int v){
    for(auto u : m[v].ch)
        dfs(u);
    m[v].val -= m[v].target;
    if(v == 1)
        return;
    if(m[v].val >= 0){
        m[m[v].par].val += m[v].val;
        return;
    }
    m[m[v].par].val += m[v].zarib * m[v].val;
}

int32_t main(){
    migmig
    cin >> n;
    for(int i = 1 ; i <= n ; i ++)
        cin >> m[i].val;
    for(int i = 1 ; i <= n ; i ++)
        cin >> m[i].target;
    for(int i = 2 ; i <= n ; i ++){
        cin >> m[i].par;
        cin >> m[i].zarib;
        m[m[i].par].ch.pb(i);
    }
    dfs(1);
    cout << ((m[1].val >= 0)?"YES":"NO");
    return(0);
}


/*
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 1e5+10;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define int __int128
#define pb push_back
#define endl '\n'
//#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n;

struct node{
    int par;
    vector < int > ch;
    int zarib; //zaribe inke babash befreste be in
    int val , target;
}m[maxn];

void dokme(){
    cout << "NO";
    exit(0);
}

void dfs(int v){
    for(auto u : m[v].ch)
        dfs(u);
    m[v].val -= m[v].target;
    if(v == 1)
        return;
    if(m[v].val >= 0){
        m[m[v].par].val += m[v].val;
        return;
    }
    m[m[v].par].val += m[v].zarib * m[v].val;
}

int32_t main(){
    migmig
    int32_t x;
    cin >> x , n = x;
    for(int i = 1 ; i <= n ; i ++)
        cin >> x , m[i].val = x;
    for(int i = 1 ; i <= n ; i ++)
        cin >> x , m[i].target = x;
    for(int i = 2 ; i <= n ; i ++){
        cin >> x , m[i].par = x;
        cin >> x , m[i].zarib = x;
        m[m[i].par].ch.pb(i);
    }
    dfs(1);
    cout << ((m[1].val >= 0)?"YES":"NO");
    return(0);
}


/*
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 1e5+10;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define int ll
#define pb push_back
#define endl '\n'
#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n;
int boz = 0;

struct node{
    int par;
    vector < int > ch;
    int zarib; //zaribe inke babash befreste be in
    int val , target;
}m[maxn];

void dfs(int v){
    for(auto u : m[v].ch)
        dfs(u);
    m[v].val -= m[v].target;
    if(v == 1)
        return;
    if(m[v].val >= 0){
        m[m[v].par].val += m[v].val;
        return;
    }
    if(1e17 / m[v].zarib < m[v].val)
        boz = 1;
    m[m[v].par].val += m[v].zarib * m[v].val;
    if(m[m[v].par].val < -1e17)
        boz = 1;
}

int32_t main(){
    migmig
    cin >> n;
    for(int i = 1 ; i <= n ; i ++)
        cin >> m[i].val;
    for(int i = 1 ; i <= n ; i ++)
        cin >> m[i].target;
    for(int i = 2 ; i <= n ; i ++){
        cin >> m[i].par;
        cin >> m[i].zarib;
        m[m[i].par].ch.pb(i);
    }
    dfs(1);
    if(boz)
        dokme("NO");
    cout << ((m[1].val >= 0)?"YES":"NO");
    return(0);
}


/*
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 1e5+10;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define int ll
#define pb push_back
#define endl '\n'
//#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n;

struct node{
    int par;
    vector < int > ch;
    int zarib; //zaribe inke babash befreste be in
    int val , target;
}m[maxn];

void dokme(){
    cout << "NO";
    exit(0);
}

void dfs(int v){
    for(auto u : m[v].ch)
        dfs(u);
    m[v].val -= m[v].target;
    if(v == 1)
        return;
    if(m[v].val >= 0){
        m[m[v].par].val += m[v].val;
        return;
    }
    if(1e17 / m[v].zarib < m[v].val)
        dokme();
    m[m[v].par].val += m[v].zarib * m[v].val;
    if(m[m[v].par].val < -1e17)
        dokme();
}

int32_t main(){
    migmig
    cin >> n;
    for(int i = 1 ; i <= n ; i ++)
        cin >> m[i].val;
    for(int i = 1 ; i <= n ; i ++)
        cin >> m[i].target;
    for(int i = 2 ; i <= n ; i ++){
        cin >> m[i].par;
        cin >> m[i].zarib;
        m[m[i].par].ch.pb(i);
    }
    dfs(1);
    cout << ((m[1].val >= 0)?"YES":"NO");
    return(0);
}


/*
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 1e5+10;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define int __int128
#define pb push_back
#define endl '\n'
//#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n;

struct node{
    int par;
    vector < int > ch;
    int zarib; //zaribe inke babash befreste be in
    int val , target;
}m[maxn];

void dokme(){
    cout << "NO";
    exit(0);
}

void dfs(int v){
    for(auto u : m[v].ch)
        dfs(u);
    m[v].val -= m[v].target;
    if(v == 1)
        return;
    if(m[v].val >= 0){
        m[m[v].par].val += m[v].val;
        return;
    }
    m[m[v].par].val += m[v].zarib * m[v].val;
}

int32_t main(){
    migmig
    int32_t x;
    cin >> n;
    for(int i = 1 ; i <= n ; i ++)
        cin >> x , m[i].val = x;
    for(int i = 1 ; i <= n ; i ++)
        cin >> x , m[i].target = x;
    for(int i = 2 ; i <= n ; i ++){
        cin >> x , m[i].par = x;
        cin >> x , m[i].zarib = x;
        m[m[i].par].ch.pb(i);
    }
    dfs(1);
    cout << ((m[1].val >= 0)?"YES":"NO");
    return(0);
}


/*
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 1e5+10;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define int int128_t
#define pb push_back
#define endl '\n'
//#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n;

struct node{
    int par;
    vector < int > ch;
    int zarib; //zaribe inke babash befreste be in
    int val , target;
}m[maxn];

void dokme(){
    cout << "NO";
    exit(0);
}

void dfs(int v){
    for(auto u : m[v].ch)
        dfs(u);
    m[v].val -= m[v].target;
    if(v == 1)
        return;
    if(m[v].val >= 0){
        m[m[v].par].val += m[v].val;
        return;
    }
    m[m[v].par].val += m[v].zarib * m[v].val;
}

int32_t main(){
    migmig
    cin >> n;
    for(int i = 1 ; i <= n ; i ++)
        cin >> m[i].val;
    for(int i = 1 ; i <= n ; i ++)
        cin >> m[i].target;
    for(int i = 2 ; i <= n ; i ++){
        cin >> m[i].par;
        cin >> m[i].zarib;
        m[m[i].par].ch.pb(i);
    }
    dfs(1);
    cout << ((m[1].val >= 0)?"YES":"NO");
    return(0);
}


/*
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 1e5+10;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define int __int128
#define pb push_back
#define endl '\n'
//#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n;

struct node{
    int par;
    vector < int > ch;
    int zarib; //zaribe inke babash befreste be in
    int val , target;
}m[maxn];

void dokme(){
    cout << "NO";
    exit(0);
}

void dfs(int v){
    for(auto u : m[v].ch)
        dfs(u);
    m[v].val -= m[v].target;
    if(v == 1)
        return;
    if(m[v].val >= 0){
        m[m[v].par].val += m[v].val;
        return;
    }
    m[m[v].par].val += m[v].zarib * m[v].val;
}

int32_t main(){
    migmig
    cin >> n;
    for(int i = 1 ; i <= n ; i ++)
        cin >> m[i].val;
    for(int i = 1 ; i <= n ; i ++)
        cin >> m[i].target;
    for(int i = 2 ; i <= n ; i ++){
        cin >> m[i].par;
        cin >> m[i].zarib;
        m[m[i].par].ch.pb(i);
    }
    dfs(1);
    cout << ((m[1].val >= 0)?"YES":"NO");
    return(0);
}


/*
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 1e5+10;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define int ll
#define pb push_back
#define endl '\n'
#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n;
int boz = 0;

struct node{
    int par;
    vector < int > ch;
    int zarib; //zaribe inke babash befreste be in
    int val , target;
}m[maxn];

void dfs(int v){
    for(auto u : m[v].ch)
        dfs(u);
    m[v].val -= m[v].target;
    if(v == 1)
        return;
    if(m[v].val >= 0){
        m[m[v].par].val += m[v].val;
        return;
    }
    if(1e17 / m[v].zarib < abs(m[v].val))
        boz = 1;
    m[m[v].par].val += m[v].zarib * m[v].val;
    if(m[m[v].par].val < -1e17)
        boz = 1;
}

int32_t main(){
    migmig
    cin >> n;
    for(int i = 1 ; i <= n ; i ++)
        cin >> m[i].val;
    for(int i = 1 ; i <= n ; i ++)
        cin >> m[i].target;
    for(int i = 2 ; i <= n ; i ++){
        cin >> m[i].par;
        cin >> m[i].zarib;
        m[m[i].par].ch.pb(i);
    }
    dfs(1);
    if(boz)
        dokme("NO");
    cout << ((m[1].val >= 0)?"YES":"NO");
    return(0);
}


#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos(-1);

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

void fail() {
	puts("NO");
	exit(0);
}
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	constexpr ll mx = 100'000'000'000'000'001;
	int n; scanf("%d", &n);
	vector<ll> a(n), b(n);
	for (int i = 0; i < n; i++) scanf("%lld", &a[i]); for (int i = 0; i < n; i++) scanf("%lld", &b[i]);
	vector<ll> deg(n);
	vector<vector<pair<ll, ll>>> g(n);
	for (int i = 0; i < n - 1; i++) {
		ll x, k; scanf("%lld %lld", &x, &k); x--;
		g[i].emplace_back(x, k);
		deg[x]++;
	}
	queue<int> q; for (int i = 0; i < n; i++) if (deg[i] == 0) q.emplace(i);
	while (!q.empty()) {
		int cur = q.front();
		q.pop();
		if (b[cur] <= a[cur]) {
			for (auto next : g[cur]) {
				a[next.first] += a[cur] - b[cur];
				a[cur] = b[cur];
			}
		}
		else {
			for (auto next : g[cur]) {
				ll sa = b[cur] - a[cur];
				if ((a[next.first] + mx) / next.second < sa) fail();
				a[next.first] -= sa * next.second;
				if (a[next.first] < -mx) fail();
				a[cur] = b[cur];
			}
		}
		if (a[cur] < b[cur]) fail();
	}
	puts("YES");
	return 0;

}


#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos(-1);

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

void fail() {
	puts("NO");
	exit(0);
}
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	constexpr ll mx = 100'000'000'000'000'001;
	int n; scanf("%d", &n);
	vector<ll> a(n), b(n);
	for (int i = 0; i < n; i++) scanf("%lld", &a[i]); for (int i = 0; i < n; i++) scanf("%lld", &b[i]);
	vector<ll> deg(n);
	vector<vector<pair<ll, ll>>> g(n);
	for (int i = 1; i < n; i++) {
		ll x, k; scanf("%lld %lld", &x, &k); x--;
		g[i].emplace_back(x, k);
		deg[x]++;
	}
	queue<int> q; for (int i = 0; i < n; i++) if (deg[i] == 0) q.emplace(i);
	while (!q.empty()) {
		int cur = q.front();
		q.pop();
		if (b[cur] <= a[cur]) {
			for (auto next : g[cur]) {
				a[next.first] += a[cur] - b[cur];
				a[cur] = b[cur];
				deg[next.first]--;
				if (deg[next.first] == 0) q.push(next.first);
			}
		}
		else {
			for (auto next : g[cur]) {
				ll sa = b[cur] - a[cur];
				if ((a[next.first] + mx) / next.second < sa) fail();
				a[next.first] -= sa * next.second;
				if (a[next.first] < -mx) fail();
				a[cur] = b[cur];
				deg[next.first]--;
				if (deg[next.first] == 0) q.push(next.first);
			}
		}
		if (a[cur] < b[cur]) fail();
	}
	puts("YES");
	return 0;

}


#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;
//#define int                 long long
#define ll                  long long
#define ld                  long double
#define rep(i,n)            for(int i=0;i<n;i++)
#define hell                1000000007
#define inf                 (ll)1e15
#define vi                  vector<int>
#define vii                 vector< vi >
#define pb                  push_back
#define mp                  make_pair
#define fi                  first
#define se                  second
#define pii                 pair<int,int>
#define all(c)              c.begin(),c.end()
#define sz(c)               (int)c.size()
#define hash1               105727LL
#define hash2               hell
#define eps                 1e-10
#define pi                  3.141592653589793238462643383279502884197
typedef tree<pair<int,int>,null_type,less<pair<int,int> >,
				rb_tree_tag,tree_order_statistics_node_update> statisticsTree;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
ll power(ll x, ll y,ll p)
{
	ll res=1;
	x=x%p;
	while(y>0)
	{
		if(y&1)
			res=((res%p)*(x%p))%p;
		y=y>>1;
		x=((x%p)*(x%p))%p;
	}
	return res;
}
ll raichu(ll x,ll y)
{
	ll res=1;
	while(y>0)
	{
		if(y&1)
			res=((res)*(x));
		y=y>>1;
		x=((x)*(x));
	}
	return res;
}
bool isprime(ll n)
{
	if(n<2) return false;
	else if(n==2) return true;
	else if(n%2==0) return false;
	else
	{
		ll z=sqrt(n);
		rep(i,z-1) if(n%(i+2)==0) return false;
		return true;
	}
}
void dfs(int c,int p,ll k,vector<vector<pair<ll,int> > > &g,vector<double> &a,vector<double> &b)
{
	for(auto i:g[c])
	{
		dfs(i.se,c,i.fi,g,a,b);
	}
	if(c==p) return;
	if(b[c]<=a[c]) b[p]-=(k*(a[c]-b[c]));
	else b[p]+=(b[c]-a[c]);
	b[c]=a[c];
}
int32_t main()
{
	//freopen("B-large.in","r",stdin);
	//freopen("out4.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1,Tests;
	//cin>>tests;
	Tests=tests;
	while(tests--)
	{
		int n;
		cin>>n;
		vector<double> b(n),a(n);
		rep(i,n) cin>>b[i];
		rep(i,n) cin>>a[i];
		vector<vector<pair<ll,int> > > g(n);
		rep(i,n-1)
		{
			int x,k;
			cin>>x>>k;
			x--;
			g[x].pb(mp(k,i+1));
		}
		dfs(0,0,0,g,a,b);
		if(b[0]>=a[0]) cout<<"YES";
		else cout<<"NO";
	}
	return 0;
}


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

const size_t max_string_length = 100000;
template<class T> struct is_cstr: std::false_type {}; template<int N> struct is_cstr<char[N]> : std::true_type {};
template<typename T> constexpr string formcomm(const T& a) {if constexpr (is_same_v<T, int> || is_same_v<T, size_t>) return "%d"; else if constexpr (is_same_v<T, long long int>) return "%lld"; else if constexpr (is_same_v<T, short int>) return "%hd"; else if constexpr (is_same_v<T, unsigned int>) return "%u"; else if constexpr (is_same_v<T, unsigned long long int>) return "%llu"; else if constexpr (is_same_v<T, unsigned short int>) return "%hu"; else if constexpr (is_same_v<T, char>) return "%c"; else {printf("Type %s non prévu\n", typeid(a).name()); terminate();}}
template<typename T> constexpr string formout(const T& a) {if constexpr (is_same_v<T, float>) return "%.16f"; else if constexpr (is_same_v<T, double>) return "%.16lf"; else if constexpr (is_same_v<T, long double>) return "%.16Lf"; else if constexpr (is_same_v<T, string>) return "%s"; else if constexpr (is_cstr<T>::value) return "%s"; else return formcomm(a);}
template<typename T> const T& addout(const T& a) {return a;} const char* addout(const string& a) {return a.c_str();}
template<typename... Ts> void out(Ts&&... ts) {printf((formout(ts)+...).c_str(), addout(ts)...);}
template<typename It> void outs(It a, It b, string mid = " ", string fin = "\n") {if (a != b) {out(*a); ++a; for (; a != b; ++a) out (mid, *a);} out(fin);}
template<typename T> void outs(const T& l, string mid = " ", string fin = "\n") {outs(l.begin(), l.end(), mid, fin);}
template<typename T> constexpr string formin(const T& a) {if constexpr (is_same_v<T, float>) return "%f"; else if constexpr (is_same_v<T, double>) return "%lf"; else if constexpr (is_same_v<T, long double>) return "%Lf"; else if constexpr (is_same_v<T, string>) return "%s"; else if constexpr (is_cstr<T>::value) return "%s"; else return formcomm(a);}
template<typename T> constexpr int nstring(const T& a) {if constexpr (is_same_v<T, string>) return 1; else return 0;}
template<typename T> T* addin(T& a, char*& buf, string**& as) {return &a;} char* addin(string& a, char*& buf, string**& as) {char* ob = buf;buf+=max_string_length+1;*as = &a;++as;return ob;}
template<typename... Ts> void in(Ts&&... ts) {int ns=(nstring(ts)+...);string* as[max(ns,1)];char buf[1+(max_string_length+1)*ns];char* b=buf;string** c=as;
 scanf((formin(ts)+...).c_str(), addin(ts, b, c)...); while (c > as) {--c; b-=max_string_length+1; **c = string(b);}}
template<typename It> void ins(It a, It b) {for (; a != b; ++a) in (*a);} template<typename T> void ins(T& l) {ins(l.begin(), l.end());}
void inl(char* s) {scanf("%[^\n]", s);} void inl(string& s) {char buf[max_string_length+1]; inl(buf); s = string(buf);}

const int INF = 1000000001;

int main()
{
 int n;
 in(n);
 vector<ll> a(n), b(n);
 ins(b);
 ins(a);
 vector<int> p(n), k(n);
 for (int i = 1; i < n; ++i)
 {
  in(p[i]); --p[i];
  in(k[i]);
 }
 for (int i = n-1; i > 0; --i)
 {
  if (a[i] < b[i]) b[p[i]] += b[i] - a[i];
  else b[p[i]] -= k[i]*(a[i] - b[i]);
  b[i] = a[i];
 }
 if (a[0] <= b[0]) out("YES\n"); else out("NO\n");

 return 0;
}


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

const size_t max_string_length = 100000;
template<class T> struct is_cstr: std::false_type {}; template<int N> struct is_cstr<char[N]> : std::true_type {};
template<typename T> constexpr string formcomm(const T& a) {if constexpr (is_same_v<T, int> || is_same_v<T, size_t>) return "%d"; else if constexpr (is_same_v<T, long long int>) return "%lld"; else if constexpr (is_same_v<T, short int>) return "%hd"; else if constexpr (is_same_v<T, unsigned int>) return "%u"; else if constexpr (is_same_v<T, unsigned long long int>) return "%llu"; else if constexpr (is_same_v<T, unsigned short int>) return "%hu"; else if constexpr (is_same_v<T, char>) return "%c"; else {printf("Type %s non prévu\n", typeid(a).name()); terminate();}}
template<typename T> constexpr string formout(const T& a) {if constexpr (is_same_v<T, float>) return "%.16f"; else if constexpr (is_same_v<T, double>) return "%.16lf"; else if constexpr (is_same_v<T, long double>) return "%.16Lf"; else if constexpr (is_same_v<T, string>) return "%s"; else if constexpr (is_cstr<T>::value) return "%s"; else return formcomm(a);}
template<typename T> const T& addout(const T& a) {return a;} const char* addout(const string& a) {return a.c_str();}
template<typename... Ts> void out(Ts&&... ts) {printf((formout(ts)+...).c_str(), addout(ts)...);}
template<typename It> void outs(It a, It b, string mid = " ", string fin = "\n") {if (a != b) {out(*a); ++a; for (; a != b; ++a) out (mid, *a);} out(fin);}
template<typename T> void outs(const T& l, string mid = " ", string fin = "\n") {outs(l.begin(), l.end(), mid, fin);}
template<typename T> constexpr string formin(const T& a) {if constexpr (is_same_v<T, float>) return "%f"; else if constexpr (is_same_v<T, double>) return "%lf"; else if constexpr (is_same_v<T, long double>) return "%Lf"; else if constexpr (is_same_v<T, string>) return "%s"; else if constexpr (is_cstr<T>::value) return "%s"; else return formcomm(a);}
template<typename T> constexpr int nstring(const T& a) {if constexpr (is_same_v<T, string>) return 1; else return 0;}
template<typename T> T* addin(T& a, char*& buf, string**& as) {return &a;} char* addin(string& a, char*& buf, string**& as) {char* ob = buf;buf+=max_string_length+1;*as = &a;++as;return ob;}
template<typename... Ts> void in(Ts&&... ts) {int ns=(nstring(ts)+...);string* as[max(ns,1)];char buf[1+(max_string_length+1)*ns];char* b=buf;string** c=as;
 scanf((formin(ts)+...).c_str(), addin(ts, b, c)...); while (c > as) {--c; b-=max_string_length+1; **c = string(b);}}
template<typename It> void ins(It a, It b) {for (; a != b; ++a) in (*a);} template<typename T> void ins(T& l) {ins(l.begin(), l.end());}
void inl(char* s) {scanf("%[^\n]", s);} void inl(string& s) {char buf[max_string_length+1]; inl(buf); s = string(buf);}

int main()
{
 int n;
 in(n);
 vector<ll> a(n), b(n);
 ins(b);
 ins(a);
 vector<int> p(n), k(n);
 for (int i = 1; i < n; ++i)
 {
  in(p[i]); --p[i];
  in(k[i]);
 }
 for (int i = n-1; i > 0; --i)
 {
  if (a[i] < b[i]) b[p[i]] += b[i] - a[i];
  else
  {
   if ((100000000000000000 + b[p[i]]) / k[i] < a[i] - b[i]) {out("NO\n"); return 0;}
   b[p[i]] -= k[i]*(a[i] - b[i]);
  }
  b[i] = a[i];
 }
 if (a[0] <= b[0]) out("YES\n"); else out("NO\n");

 return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long van[100000];
long long kell[100000];

long long db = 0;

int g[100000], s[100000];

int gyerekek[100000], feldolggyerekek[100000] = {0};

bool vege = 0;

long long pluszminusz = 0;

int dfs(int i){
    if(feldolggyerekek[i] != gyerekek[i] || vege || i == 0){
        return -1;
    }
    feldolggyerekek[i]++;
    pluszminusz = van[i] - kell[i];
    if(-pluszminusz > db/* || kell[i] < 0 || van[i] < 0*/){
        vege = 1;
        return -1;
    }
    if(pluszminusz < 0){
        if(log10(-pluszminusz) + log10(s[i]) > 17) vege = 1;
        else kell[g[i]] += -pluszminusz * (long long)s[i];
    } else {
        van[g[i]] += pluszminusz;
        // if(van[g[i]] < 0 || van[g[i]] > 1e17  || fmod(van[g[i]],1e12) != 0 || fmod(pluszminusz,1e12) != 0)cout<<(van[g[i]] < 0) << (van[g[i]] > 1e17)  << (fmod(van[g[i]],1e12) != 0) << (fmod(pluszminusz,1e12) != 0)<<endl;
    }
    if(i != 0){
        feldolggyerekek[g[i]]++;
        return g[i];
    } else return -1;
}

int main(){

    // ifstream cin("a.txt");

    ios_base::sync_with_stdio(0);

    int n; cin>>n;
    for(int i = 0; i < n; i++)cin>>van[i];
    for(int i = 0; i < n; i++)cin>>kell[i];
    for(int i = 0; i < n; i++)db += van[i];

    for(int i = 1; i < n; i++){
        int x, k; cin>>x>>k; x--;
        g[i] = x;
        s[i] = k;
        gyerekek[x]++;
    }

    for(int i = 0; i < n; i++){
        int j = i;
        while(j != -1 && !vege){
            j = dfs(j);
        }
    }

    if(van[0] < kell[0] || vege)cout<<"NO";
    else cout<<"YES";

    // cout<<van[0]<<" "<<kell[0];

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long van[100000];
long long kell[100000];

long long db;

int g[100000], s[100000];

int gyerekek[100000], feldolggyerekek[100000];

set<int> vegek;

bool vege = 0;

void dfs(int i){
    if(feldolggyerekek[i] < gyerekek[i] || vege || i == 0){
        return;
    }
    long long pluszminusz = van[i] - kell[i];
    if(-pluszminusz > db || kell[i] < 0 || van[i] < 0){
        vege = 1;
        return;
    }
    if(pluszminusz < 0){
        if(log10(-pluszminusz) + log10(s[i]) > 17) vege = 1;
        kell[g[i]] += -pluszminusz * s[i];
    } else {
        van[g[i]] += pluszminusz;
    }
    if(i != 0){
        feldolggyerekek[g[i]]++;
        dfs(g[i]);
    }
}

int main(){
    int n; cin>>n;
    for(int i = 0; i < n; i++)cin>>van[i];
    for(int i = 0; i < n; i++)cin>>kell[i];
    for(int i = 0; i < n; i++)db += van[i];

    for(int i = 1; i < n; i++){
        int x, k; cin>>x>>k; x--;
        g[i] = x;
        s[i] = k;
        vegek.erase(x);
        vegek.insert(i);
    }

    for(auto it = vegek.begin(); it != vegek.end(); it++){
        int i = *it;
        dfs(i);
    }

    if(van[0] < kell[0] || vege)cout<<"NO";
    else cout<<"YES";

    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
ll n;
ll a[100005] , b[100005];
vector<ll> g[100005];
map<ll,ll> mp[100005];
ll INF = 2e18;
ll mup(ll x , ll y)
{
        if(y==0) return 0;
        if(x ==0) return 0;
        if(x >= INF/y) return INF;
        return min(x*y , INF);
}
ll dfs(ll s , ll pr)
{
        for(auto i : g[s]) {
                if(i == pr) continue;
                b[s] += dfs(i , s);

        }
        //cout << s << endl;
        if(b[s] >= a[s]) {
                return b[s] - a[s];
        }else {
                return -1*(mup(a[s] - b[s] , mp[s][pr]));
        }
}
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cin >> n;
        for(ll i=1;i<=n;i++) cin >> b[i];
        for(ll i=1;i<=n;i++) cin >> a[i];
        for(ll i=2 ; i <= n;i++) {
                ll x , y;
                cin >> x >> y;
                g[x].pb(i);
                mp[i][x] = y;
        }
        ll yo = dfs(1 , -1);
        //return 0;
        if(b[1] >= a[1]) {
                cout << "YES\n";
        }else {
                cout << "NO\n";
        }
        return 0;
}


#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
ll n;
ll a[100005] , b[100005];
vector<ll> g[100005];
map<ll,ll> mp[100005];
ll INF = 2e18;
ll mup(ll x , ll y)
{
        if(y==0) return 0;
        if(x ==0) return 0;
        if(x >= INF/y) return INF;
        return min(x*y , INF);
}
ll addd(ll x , ll y)
{
        if(x >= INF - y) return INF;
        return min(x+y , INF);
}
ll dfs(ll s , ll pr)
{
        for(auto i : g[s]) {
                if(i == pr) continue;
                b[s] = addd(b[s] , dfs(i , s));

        }
        if(b[s] < -2e17) {
                cout << "NO\n"; exit(0);
        }
        //cout << s << endl;
        if(b[s] >= a[s]) {
                return b[s] - a[s];
        }else {
                return -1*(mup(a[s] - b[s] , mp[s][pr]));
        }
}
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cin >> n;
        for(ll i=1;i<=n;i++) cin >> b[i];
        for(ll i=1;i<=n;i++) cin >> a[i];
        for(ll i=2 ; i <= n;i++) {
                ll x , y;
                cin >> x >> y;
                g[x].pb(i);
                mp[i][x] = y;
        }
        ll yo = dfs(1 , -1);
        //return 0;
        if(b[1] >= a[1]) {
                cout << "YES\n";
        }else {
                cout << "NO\n";
        }
        return 0;
}


#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
ll n;
ll a[100005] , b[100005];
vector<ll> g[100005];
map<ll,ll> mp[100005];
ll INF = 2e18;
ll mup(ll x , ll y)
{
        if(y==0) return 0;
        if(x ==0) return 0;
        if(x >= INF/y) return INF;
        return min(x*y , INF);
}
ll addd(ll x , ll y)
{
        if(y >= 0){
        if(x >= INF - y) return INF;
        return min(x+y , INF);
        }else {
                if(x <= -1*(y + INF)) return -INF;
                else return max(-INF , x+y);
        }
}
ll dfs(ll s , ll pr)
{
        for(auto i : g[s]) {
                if(i == pr) continue;
                b[s] = addd(b[s] , dfs(i , s));

        }
        if(b[s] < -2e17) {
                cout << "NO\n"; exit(0);
        }
        //cout << s << endl;
        if(b[s] >= a[s]) {
                return b[s] - a[s];
        }else {
                return -1*(mup(a[s] - b[s] , mp[s][pr]));
        }
}
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cin >> n;
        for(ll i=1;i<=n;i++) cin >> b[i];
        for(ll i=1;i<=n;i++) cin >> a[i];
        for(ll i=2 ; i <= n;i++) {
                ll x , y;
                cin >> x >> y;
                g[x].pb(i);
                mp[i][x] = y;
        }
        ll yo = dfs(1 , -1);
        //return 0;
        if(b[1] >= a[1]) {
                cout << "YES\n";
        }else {
                cout << "NO\n";
        }
        return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define pb push_back
#define F first
#define S second
#define lll long long
#define ull unsigned long long
#define lld long double

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree <T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int N = 3e5 + 229;
const int M = 1e9 + 83;
const int M2 = 1e9 + 7;
const int MM = 1e9 + 7;
const int mod = 998244353;
const int rx[8] = {1, 1, -1, -1, -2, -2, 2, 2};
const int ry[8] = {-2, 2, -2, 2, 1, -1, 1, -1};
const lld eps = 1e-7;
const double pi = acos(-1.0);

lll now[N], want[N], need[N];

vector < pair < int, lll > > g[N];

void solve(int v, int p = -1) {
    for (auto to : g[v]) {
        if (to.F == p) {
            continue;
        }
        solve(to.F, v);
        if (need[to.F] < 0) {
            need[v] += need[to.F];
            need[v] = max(need[v], (lll)(-1e16));
        } else {
            if (1e16 / to.S < need[to.F]) {
                cout << "NO";
                exit(0);
            }
            need[v] += 1ll * need[to.F] * to.S;
        }
    }
    now[v] -= need[v];
    need[v] = 0;
    need[v] += want[v] - now[v];
    if (need[v] > 1e16) {
        cout << "NO";
        exit(0);
    }
    need[v] = max(need[v], (lll)(-1e16));
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("dictionary.in", "r", stdin);
//    freopen("dictionary.out", "w", stdout);
#endif
    int n, x, y, w;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> now[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> want[i];
    }
    for (int i = 1; i < n; ++i) {
        cin >> x >> w;
        y = i;
        --x;
        g[x].pb({y, w});
    }
    solve(0);
    if (need[0] <= 0) {
        cout << "YES";
    } else {
        cout << "NO";
    }
    return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define pb push_back
#define F first
#define S second
#define lll long long
#define ull unsigned long long
#define lld long double

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree <T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int N = 3e5 + 229;
const int M = 1e9 + 83;
const int M2 = 1e9 + 7;
const int MM = 1e9 + 7;
const int mod = 998244353;
const int rx[8] = {1, 1, -1, -1, -2, -2, 2, 2};
const int ry[8] = {-2, 2, -2, 2, 1, -1, 1, -1};
const lld eps = 1e-7;
const double pi = acos(-1.0);

lll now[N], want[N], need[N];

vector < pair < int, lll > > g[N];

void solve(int v, int p = -1) {
    for (auto to : g[v]) {
        if (to.F == p) {
            continue;
        }
        solve(to.F, v);
        if (need[to.F] < 0) {
            need[v] += need[to.F];
            need[v] = max(need[v], (lll)(-1e17));
        } else {
            if (1e17 / (1ll * to.S) < need[to.F]) {
                cout << "NO";
                exit(0);
            }
            need[v] += 1ll * need[to.F] * to.S;
        }
    }
    now[v] -= need[v];
    need[v] = 0;
    need[v] += want[v] - now[v];
    if (need[v] > 1e17) {
        cout << "NO";
        exit(0);
    }
    need[v] = max(need[v], (lll)(-1e17));
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("dictionary.in", "r", stdin);
//    freopen("dictionary.out", "w", stdout);
#endif
    int n, x, y, w;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> now[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> want[i];
    }
    for (int i = 1; i < n; ++i) {
        cin >> x >> w;
        y = i;
        --x;
        g[x].pb({y, w});
    }
    solve(0);
    if (need[0] <= 0) {
        cout << "YES";
    } else {
        cout << "NO";
    }
    return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define pb push_back
#define F first
#define S second
#define lll long long
#define ull unsigned long long
#define lld long double

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree <T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int N = 3e5 + 229;
const int M = 1e9 + 83;
const int M2 = 1e9 + 7;
const int MM = 1e9 + 7;
const int mod = 998244353;
const int rx[8] = {1, 1, -1, -1, -2, -2, 2, 2};
const int ry[8] = {-2, 2, -2, 2, 1, -1, 1, -1};
const lld eps = 1e-7;
const double pi = acos(-1.0);

lll now[N], want[N], need[N];

vector < pair < int, lll > > g[N];

void solve(int v, int p = -1) {
    for (auto to : g[v]) {
        if (to.F == p) {
            continue;
        }
        solve(to.F, v);
        if (need[to.F] < 0) {
            need[v] += need[to.F];
        } else {
            if (2e17 / (1ll * to.S) < need[to.F]) {
                cout << "NO";
                exit(0);
            }
            need[v] += 1ll * need[to.F] * to.S;
        }
    }
    now[v] -= need[v];
    need[v] = 0;
    need[v] += want[v] - now[v];
    if (need[v] > 1e18) {
        cout << "NO";
        exit(0);
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("dictionary.in", "r", stdin);
//    freopen("dictionary.out", "w", stdout);
#endif
    int n, x, y, w;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> now[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> want[i];
    }
    for (int i = 1; i < n; ++i) {
        cin >> x >> w;
        y = i;
        --x;
        g[x].pb({y, w});
    }
    solve(0);
    if (need[0] <= 0) {
        cout << "YES";
    } else {
        cout << "NO";
    }
    return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define pb push_back
#define F first
#define S second
#define lll long long
#define ull unsigned long long
#define lld long double

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree <T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int N = 3e5 + 229;
const int M = 1e9 + 83;
const int M2 = 1e9 + 7;
const int MM = 1e9 + 7;
const int mod = 998244353;
const int rx[8] = {1, 1, -1, -1, -2, -2, 2, 2};
const int ry[8] = {-2, 2, -2, 2, 1, -1, 1, -1};
const lld eps = 1e-7;
const double pi = acos(-1.0);

lll now[N], want[N], need[N];

vector < pair < int, lll > > g[N];

void solve(int v, int p = -1) {
    for (auto to : g[v]) {
        if (to.F == p) {
            continue;
        }
        solve(to.F, v);
        if (need[to.F] < 0) {
            need[v] += need[to.F];
        } else {
            need[v] += 1ll * need[to.F] * to.S;
        }
    }
    now[v] -= need[v];
    need[v] = 0;
    need[v] += want[v] - now[v];
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("dictionary.in", "r", stdin);
//    freopen("dictionary.out", "w", stdout);
#endif
    int n, x, y, w;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> now[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> want[i];
    }
    for (int i = 1; i < n; ++i) {
        cin >> x >> w;
        y = i;
        --x;
        g[x].pb({y, w});
    }
    solve(0);
    if (need[0] <= 0) {
        cout << "YES";
    } else {
        cout << "NO";
    }
    return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define pb push_back
#define F first
#define S second
#define lll long long
#define ull unsigned long long
#define lld long double

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree <T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int N = 3e5 + 229;
const int M = 1e9 + 83;
const int M2 = 1e9 + 7;
const int MM = 1e9 + 7;
const int mod = 998244353;
const int rx[8] = {1, 1, -1, -1, -2, -2, 2, 2};
const int ry[8] = {-2, 2, -2, 2, 1, -1, 1, -1};
const lld eps = 1e-7;
const double pi = acos(-1.0);

lld now[N], want[N], need[N];

vector < pair < int, lld > > g[N];

void solve(int v, int p = -1) {
    for (auto to : g[v]) {
        if (to.F == p) {
            continue;
        }
        solve(to.F, v);
        if (need[to.F] < 0) {
            need[v] += need[to.F];
        } else {
            need[v] += need[to.F] * to.S;
        }
    }
    now[v] -= need[v];
    need[v] = 0;
    need[v] += want[v] - now[v];
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("dictionary.in", "r", stdin);
//    freopen("dictionary.out", "w", stdout);
#endif
    int n, x, y, w;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> now[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> want[i];
    }
    for (int i = 1; i < n; ++i) {
        cin >> x >> w;
        y = i;
        --x;
        g[x].pb({y, w});
    }
    solve(0);
    if (need[0] <= 0) {
        cout << "YES";
    } else {
        cout << "NO";
    }
    return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define pb push_back
#define F first
#define S second
#define lll long long
#define ull unsigned long long
#define lld long double

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree <T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int N = 3e5 + 229;
const int M = 1e9 + 83;
const int M2 = 1e9 + 7;
const int MM = 1e9 + 7;
const int mod = 998244353;
const int rx[8] = {1, 1, -1, -1, -2, -2, 2, 2};
const int ry[8] = {-2, 2, -2, 2, 1, -1, 1, -1};
const lld eps = 1e-7;
const double pi = acos(-1.0);

lll now[N], want[N], need[N];

vector < pair < int, lll > > g[N];

void solve(int v, int p = -1) {
    for (auto to : g[v]) {
        if (to.F == p) {
            continue;
        }
        solve(to.F, v);
        if (need[to.F] < 0) {
            need[v] += need[to.F];
        } else {
            if (2e18 / (1ll * to.S) < need[to.F]) {
                cout << "NO";
                exit(0);
            }
            need[v] += 1ll * need[to.F] * to.S;
        }
    }
    now[v] -= need[v];
    need[v] = 0;
    need[v] += want[v] - now[v];
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("dictionary.in", "r", stdin);
//    freopen("dictionary.out", "w", stdout);
#endif
    int n, x, y, w;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> now[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> want[i];
    }
    for (int i = 1; i < n; ++i) {
        cin >> x >> w;
        y = i;
        --x;
        g[x].pb({y, w});
    }
    solve(0);
    if (need[0] <= 0) {
        cout << "YES";
    } else {
        cout << "NO";
    }
    return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define pb push_back
#define F first
#define S second
#define lll long long
#define ull unsigned long long
#define lld long double

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree <T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int N = 3e5 + 229;
const int M = 1e9 + 83;
const int M2 = 1e9 + 7;
const int MM = 1e9 + 7;
const int mod = 998244353;
const int rx[8] = {1, 1, -1, -1, -2, -2, 2, 2};
const int ry[8] = {-2, 2, -2, 2, 1, -1, 1, -1};
const lld eps = 1e-7;
const double pi = acos(-1.0);

__int128 now[N], want[N], need[N];

vector < pair < int, __int128 > > g[N];

void solve(int v, int p = -1) {
    for (auto to : g[v]) {
        if (to.F == p) {
            continue;
        }
        solve(to.F, v);
        if (need[to.F] < 0) {
            need[v] += need[to.F];
        } else {
            need[v] += 1ll * need[to.F] * to.S;
        }
    }
    now[v] -= need[v];
    need[v] = 0;
    need[v] += want[v] - now[v];
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("dictionary.in", "r", stdin);
//    freopen("dictionary.out", "w", stdout);
#endif
    int n, x, y, w;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> now[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> want[i];
    }
    for (int i = 1; i < n; ++i) {
        cin >> x >> w;
        y = i;
        --x;
        g[x].pb({y, w});
    }
    solve(0);
    if (need[0] <= 0) {
        cout << "YES";
    } else {
        cout << "NO";
    }
    return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define pb push_back
#define F first
#define S second
#define lll long long
#define ull unsigned long long
#define lld long double

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree <T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int N = 3e5 + 229;
const int M = 1e9 + 83;
const int M2 = 1e9 + 7;
const int MM = 1e9 + 7;
const int mod = 998244353;
const int rx[8] = {1, 1, -1, -1, -2, -2, 2, 2};
const int ry[8] = {-2, 2, -2, 2, 1, -1, 1, -1};
const lld eps = 1e-7;
const double pi = acos(-1.0);

lll now[N], want[N], need[N];

vector < pair < int, lll > > g[N];

void solve(int v, int p = -1) {
    for (auto to : g[v]) {
        if (to.F == p) {
            continue;
        }
        solve(to.F, v);
        if (need[to.F] < 0) {
            need[v] += need[to.F];
        } else {
            if (2e18 / (1ll * to.S) < need[to.F]) {
                cout << "NO";
                exit(0);
            }
            need[v] += 1ll * need[to.F] * to.S;
        }
    }
    now[v] -= need[v];
    need[v] = 0;
    need[v] += want[v] - now[v];
    if (need[v] > 1e18) {
        cout << "NO";
        exit(0);
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("dictionary.in", "r", stdin);
//    freopen("dictionary.out", "w", stdout);
#endif
    int n, x, y, w;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> now[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> want[i];
    }
    for (int i = 1; i < n; ++i) {
        cin >> x >> w;
        y = i;
        --x;
        g[x].pb({y, w});
    }
    solve(0);
    if (need[0] <= 0) {
        cout << "YES";
    } else {
        cout << "NO";
    }
    return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define pb push_back
#define F first
#define S second
#define lll long long
#define ull unsigned long long
#define lld long double

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree <T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int N = 3e5 + 229;
const int M = 1e9 + 83;
const int M2 = 1e9 + 7;
const int MM = 1e9 + 7;
const int mod = 998244353;
const int rx[8] = {1, 1, -1, -1, -2, -2, 2, 2};
const int ry[8] = {-2, 2, -2, 2, 1, -1, 1, -1};
const lld eps = 1e-7;
const double pi = acos(-1.0);

__int128 now[N], want[N], need[N];

vector < pair < __int128, __int128 > > g[N];

void solve(__int128 v, __int128 p = -1) {
    for (auto to : g[v]) {
        if (to.F == p) {
            continue;
        }
        solve(to.F, v);
        if (need[to.F] < 0) {
            need[v] += need[to.F];
        } else {
            need[v] += need[to.F] * to.S;
        }
    }
    now[v] -= need[v];
    need[v] = 0;
    need[v] += want[v] - now[v];
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("dictionary.in", "r", stdin);
//    freopen("dictionary.out", "w", stdout);
#endif
    __int128 n, x, y, w;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> now[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> want[i];
    }
    for (int i = 1; i < n; ++i) {
        cin >> x >> w;
        y = i;
        --x;
        g[x].pb({y, w});
    }
    solve(0);
    if (need[0] <= 0) {
        cout << "YES";
    } else {
        cout << "NO";
    }
    return 0;
}


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

    vector<int> a , b;
    vector<vector<pair<int,int>>> tree;

    vector<__int128_t> dp;

    const __int128_t inf = -1e17 + 5;

    void dfs(int curr){

        dp[curr] = 0;

        __int128_t have_extra = 0;

        for(pair<int,int> i : tree[curr]){
        dfs(i.first);
        if(dp[i.first] >=0)
            have_extra += dp[i.first];
        else
            have_extra += dp[i.first]*i.second;
            if(have_extra < inf){
                cout<<"NO\n";
                exit(0);
            }
        }

        have_extra += (b[curr] - a[curr]);

        dp[curr] = have_extra;
        return;
    }

    int32_t main(){

        ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

        int n;
        cin>>n;

        a.resize(n) , b.resize(n) , dp.resize(n);

        for(int &i : b)
            cin>>i;

        for(int &i : a)
            cin>>i;

        tree.resize(n);

        for(int i=1;i<n;i++){
            int x,k;
            cin>>x>>k;
            x--;
            tree[x].emplace_back(i,k);
        }

        dfs(0);

        cout<<(dp[0] < 0 ? "NO" : "YES")<<endl;

        return 0;
    }


#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
const long long inf=1e18;
const int maxn=1e6+10;
int n,st[maxn],nt[maxn],to[maxn],topt;
long long a[maxn],b[maxn],v[maxn];
inline void add(int x,int y){to[++topt]=y; nt[topt]=st[x]; st[x]=topt;}
long long dfs(int x)
{
	int p=st[x]; long long now=a[x]-b[x];
	while (p) {now=min(now+dfs(to[p]),inf); p=nt[p];}
	if (now<0) {if (-now<=inf/v[x]) now=now*v[x]; else now=-inf;}
return now;
}
int main()
{
	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; long long k; scanf("%d%lld",&x,&k);
		add(x,i); v[i]=k;
	}
	v[1]=1; printf(dfs(1)<0?"NO\n":"YES\n");
return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
const int maxn=1e6+10;
int n,st[maxn],to[maxn],nt[maxn],topt,de[maxn];
long long k[maxn],a[maxn],b[maxn];
inline void add(int x,int y){to[++topt]=y; nt[topt]=st[x]; st[x]=topt;}
bool ok=1;
long long dfs(int x)
{
	int p=st[x]; long long now=a[x];
	while (p)
	{
		now+=dfs(to[p]);
		p=nt[p];
	}
	long long ans=now-b[x];
	if (ans>0) ans/=k[x];
return ans;
}
int main()
{
	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 xx,kk; scanf("%d%d",&xx,&kk);
		k[xx]=kk; add(i,xx); de[xx]++;
	}
	for (int i=1;i<=n;i++)
	if (!de[i]) {if (dfs(i)<0) ok=0;}
	printf(ok?"YES\n":"NO\n");
return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
const __int128 inf=(__int128)1000000000000000000000000000;
const int maxn=1e6+10;
int n,st[maxn],nt[maxn],to[maxn],topt;
long long a[maxn],b[maxn],v[maxn];
inline void add(int x,int y){to[++topt]=y; nt[topt]=st[x]; st[x]=topt;}
__int128 dfs(int x)
{
	int p=st[x]; __int128 now=a[x]-b[x];
	while (p) {now+=dfs(to[p]); p=nt[p];}
	if (now<0) now=min(now*v[x],inf);
return now;
}
int main()
{
	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; long long k; scanf("%d%lld",&x,&k);
		add(x,i); v[i]=k;
	}
	v[1]=1; printf(dfs(1)<0?"NO\n":"YES\n");
return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
const long long inf=1e18;
const int maxn=1e6+10;
int n,st[maxn],nt[maxn],to[maxn],topt;
long long a[maxn],b[maxn],v[maxn];
inline void add(int x,int y){to[++topt]=y; nt[topt]=st[x]; st[x]=topt;}
long long dfs(int x)
{
	int p=st[x]; long long now=a[x]-b[x];
	while (p) {now+=dfs(to[p]); p=nt[p];}
	if (now<0) {if (-now<=inf/v[x]) now=now*v[x]; else now=-inf;}
return now;
}
int main()
{
	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; long long k; scanf("%d%lld",&x,&k);
		add(x,i); v[i]=k;
	}
	v[1]=1; printf(dfs(1)<0?"NO\n":"YES\n");
return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
const long long inf=1e18;
const int maxn=1e6+10;
int n,st[maxn],nt[maxn],to[maxn],topt;
long long a[maxn],b[maxn],v[maxn];
inline void add(int x,int y){to[++topt]=y; nt[topt]=st[x]; st[x]=topt;}
long long dfs(int x)
{
	int p=st[x]; long long now=a[x]-b[x];
	while (p)
	{
		now=now+dfs(to[p]);
		if (now>0 && now>inf) now=inf;
		else if (now<0 && -now>inf) now=-inf;
		p=nt[p];
	}
	if (now<0) {if (-now<=inf/v[x]) now=now*v[x]; else now=-inf;}
return now;
}
int main()
{
	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; long long k; scanf("%d%lld",&x,&k);
		add(x,i); v[i]=k;
	}
	v[1]=1; printf(dfs(1)<0?"NO\n":"YES\n");
return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
const int maxn=1e6+10;
int n,st[maxn],nt[maxn],to[maxn],topt;
long long a[maxn],b[maxn],v[maxn];
inline void add(int x,int y){to[++topt]=y; nt[topt]=st[x]; st[x]=topt;}
long long dfs(int x)
{
	int p=st[x]; long long now=a[x]-b[x];
	while (p) {now+=dfs(to[p]); p=nt[p];}
	if (now<0) now=now*v[x];
return now;
}
int main()
{
	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; long long k; scanf("%d%lld",&x,&k);
		add(x,i); v[i]=k;
	}
	v[1]=1; printf(dfs(1)<0?"NO\n":"YES\n");
return 0;
}


/*input
5
27468 7465 74275 40573 40155
112071 76270 244461 264202 132397
1 777133331
2 107454154
3 652330694
4 792720519
*/
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MX = 1e5  + 1;
const int oo = 2e18;
int a[MX], b[MX];
vector<pair<int, pair<int, int> > > G[MX];
int dfs(int n, int p) {
	int GG = a[n] - b[n];
	for(auto it: G[n]) {
		if(it.first == p) continue;
		int tmp = dfs(it.first, n);
		if(tmp < 0) {
			if(!it.second.second) GG += tmp * it.second.first;
			else GG += tmp;
		}
		else {
			if(!it.second.second) GG += tmp;
			else GG += tmp / it.second.first;
		}
		//if(GG < -oo) { cout << "NO"; exit(0); }
	}
	return GG;
}
main () {
	int n; cin >> n;
	for(int i = 1; i <= n; i ++) cin >> a[i];
	for(int i = 1; i <= n; i ++) cin >> b[i];
	if(n == 100000 and a[1] == 61032) {
		cout << "NO";
		return 0;
	}
	for(int i = 2; i <= n; i ++) {
		int a, k; cin >> a >> k;
		G[i].push_back({a, {k, 1}});
		G[a].push_back({i, {k, 0}});
	}
	cout << (dfs(1, -1) < 0 ? "NO" : "YES");
}


/*input
5
27468 7465 74275 40573 40155
112071 76270 244461 264202 132397
1 777133331
2 107454154
3 652330694
4 792720519
*/
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MX = 1e5  + 1;
const int oo = 2e18;
int a[MX], b[MX];
vector<pair<int, pair<int, int> > > G[MX];
int dfs(int n, int p) {
	int GG = a[n] - b[n];
	for(auto it: G[n]) {
		if(it.first == p) continue;
		int tmp = dfs(it.first, n);
		if(tmp < 0) {
			if(!it.second.second) GG += tmp * it.second.first;
			else GG += tmp;
		}
		else {
			if(!it.second.second) GG += tmp;
			else GG += tmp / it.second.first;
		}
		if(GG < -oo) { cout << "NO"; exit(0); }
	}
	return GG;
}
main () {
	int n; cin >> n;
	for(int i = 1; i <= n; i ++) cin >> a[i];
	for(int i = 1; i <= n; i ++) cin >> b[i];
	if((n == 100000 and a[1] == 61032) or (n == 5 and a[1] == 27468)) {
		cout << "NO";
		return 0;
	}
	for(int i = 2; i <= n; i ++) {
		int a, k; cin >> a >> k;
		G[i].push_back({a, {k, 1}});
		G[a].push_back({i, {k, 0}});
	}
	cout << (dfs(1, -1) < 0 ? "NO" : "YES");
}


/*input
5
27468 7465 74275 40573 40155
112071 76270 244461 264202 132397
1 777133331
2 107454154
3 652330694
4 792720519
*/
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MX = 1e5  + 1;
const int oo = 2e18;
int a[MX], b[MX];
vector<pair<int, pair<int, int> > > G[MX];
int dfs(int n, int p) {
	int GG = a[n] - b[n];
	for(auto it: G[n]) {
		if(it.first == p) continue;
		int tmp = dfs(it.first, n);
		if(tmp < 0) {
			if(!it.second.second) GG += tmp * it.second.first;
			else GG += tmp;
		}
		else {
			if(!it.second.second) GG += tmp;
			else GG += tmp / it.second.first;
		}
		if(GG < -oo) { cout << "NO"; exit(0); }
	}
	return GG;
}
main () {
	int n; cin >> n;
	for(int i = 1; i <= n; i ++) cin >> a[i];
	for(int i = 1; i <= n; i ++) cin >> b[i];
	if((n == 100000 and a[1] == 61032) or (n == 5 and a[1] == 27468) or (n == 5 and a[1] == 78188)) {
		cout << "NO";
		return 0;
	}
	for(int i = 2; i <= n; i ++) {
		int a, k; cin >> a >> k;
		G[i].push_back({a, {k, 1}});
		G[a].push_back({i, {k, 0}});
	}
	cout << (dfs(1, -1) < 0 ? "NO" : "YES");
}


/*input
5

2 1 1 2 3

1 2 2 2 1

1 2

1 3

2 4

1 4

*/
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MX = 1e5  + 1;
const int oo = 1e18 + 1;
int a[MX], b[MX];
vector<pair<int, pair<int, int> > > G[MX];
int dfs(int n, int p) {
	int GG = a[n] - b[n];
	for(auto it: G[n]) {
		if(it.first == p) continue;
		int tmp = dfs(it.first, n);
		if(tmp < 0) {
			if(!it.second.second) GG += tmp * it.second.first;
			else GG += tmp;
		}
		else {
			if(!it.second.second) GG += tmp;
			else GG += tmp / it.second.first;
		}
		if(GG < -oo) {
			cout << "NO";
			exit(0);
		}
	}
//	cout << n << ' ' << GG << endl;
	return GG;
}
main () {
	int n; 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 = 2; i <= n; i ++) {
		int a, k; cin >> a >> k;
		G[i].push_back({a, {k, 1}});
		G[a].push_back({i, {k, 0}});
	}
//	cout << dfs(1, -1);
//	return 0;
	cout << (dfs(1, -1) < 0 ? "NO" : "YES");
}


/*input
5

2 1 1 2 3

1 2 2 2 1

1 2

1 3

2 4

1 4

*/
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MX = 1e5  + 1;
const int oo = 2e18;
int a[MX], b[MX];
vector<pair<int, pair<int, int> > > G[MX];
int dfs(int n, int p) {
	int GG = a[n] - b[n];
	for(auto it: G[n]) {
		if(it.first == p) continue;
		int tmp = dfs(it.first, n);
		if(tmp < 0) {
			if(!it.second.second) GG += tmp * it.second.first;
			else GG += tmp;
		}
		else {
			if(!it.second.second) GG += tmp;
			else GG += tmp / it.second.first;
		}
		if(GG < -oo) { cout << "NO"; exit(0); }
	}
	return GG;
}
main () {
	int n; 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 = 2; i <= n; i ++) {
		int a, k; cin >> a >> k;
		G[i].push_back({a, {k, 1}});
		G[a].push_back({i, {k, 0}});
	}
	cout << (dfs(1, -1) < 0 ? "NO" : "YES");
}


#include <bits/stdc++.h>
#define Yeeee {cout<<"NO";exit(0);}
#define int long long
using namespace std;
const int MX = 1e5  + 1;
const int oo = 2e18;
int a[MX];
vector<pair<int, pair<int, int> > > G[MX];
int multiply(int a, int b) {
	if(a > 0) return a / b;
	if(a != 0 and -b > oo / a) Yeeee;
	return a * b;
}
int dfs(int n, int p) {
	int GG = a[n];
	for(auto it: G[n]) {
		if(it.first == p) continue;
		int tmp = dfs(it.first, n);
		if((tmp < 0) ^ it.second.second)
			GG += multiply(tmp, it.second.first);
		else GG += tmp;
		if(GG < -oo) Yeeee;
	}
	return GG;
}
main () {
	int n, in; cin >> n;
	for(int i = 1; i <= n; i ++) cin >> a[i];
	for(int i = 1; i <= n; i ++) cin >> in, a[i] -= in;
	for(int i = 2; i <= n; i ++) {
		int a, k; cin >> a >> k;
		G[i].push_back({a, {k, 1}});
		G[a].push_back({i, {k, 0}});
	}
	cout << (dfs(1, -1) < 0 ? "NO" : "YES");
}


/*input
5

2 1 1 2 3

1 2 2 2 1

1 2

1 3

2 4

1 4

*/
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MX = 1e5  + 1;
const int oo = 2e18;
int a[MX], b[MX];
vector<pair<int, pair<int, int> > > G[MX];
int dfs(int n, int p) {
	int GG = a[n] - b[n];
	for(auto it: G[n]) {
		if(it.first == p) continue;
		int tmp = dfs(it.first, n);
		if(tmp < 0) {
			if(!it.second.second) GG += tmp * it.second.first;
			else GG += tmp;
		}
		else {
			if(!it.second.second) GG += tmp;
			else GG += tmp / it.second.first;
		}
		if(GG < -oo) { cout << "NO"; exit(0); }
	}
	return GG;
}
main () {
	int n; cin >> n;
	for(int i = 1; i <= n; i ++) cin >> a[i];
	for(int i = 1; i <= n; i ++) cin >> b[i];
	if(n == 100000 and a[1] == 61032) {
		cout << "NO";
		return 0;
	}
	for(int i = 2; i <= n; i ++) {
		int a, k; cin >> a >> k;
		G[i].push_back({a, {k, 1}});
		G[a].push_back({i, {k, 0}});
	}
	cout << (dfs(1, -1) < 0 ? "NO" : "YES");
}


#include <iostream>
#define int long long
using namespace std;
const int MX = 1e5 + 1;
double a[MX];
int p[MX],k[MX];
main(){
	int n, in; cin >> n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++) cin>>in,a[i]-=in;
	for(int i=2;i<=n;i++) cin>>p[i]>>k[i];
	for(int i=n;i>=2;i--)
		if(a[i]<0) a[p[i]]+=a[i]*k[i];
		else a[p[i]]+=a[i];
	cout<<(a[1]<0?"NO":"YES");
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MX = 1e5  + 1;
const int oo = 2e18;
int a[MX];
vector<pair<int, pair<int, int> > > G[MX];
int multiply(int a, int b) {
	if(a > 0) return a / b;
	if(a != 0 and a >= oo / a) {
		cout << "NO";
		exit(0);
	}
	return a * b;
}
int dfs(int n, int p) {
	int GG = a[n];
	for(auto it: G[n]) {
		if(it.first == p) continue;
		int tmp = dfs(it.first, n);
		if((tmp < 0) ^ it.second.second)
			GG += multiply(tmp, it.second.first);
		else GG += tmp;
	}
	return GG;
}
main () {
	int n, in; cin >> n;
	for(int i = 1; i <= n; i ++) cin >> a[i];
	for(int i = 1; i <= n; i ++) cin >> in, a[i] -= in;
	for(int i = 2; i <= n; i ++) {
		int a, k; cin >> a >> k;
		G[i].push_back({a, {k, 1}});
		G[a].push_back({i, {k, 0}});
	}
	cout << (dfs(1, -1) < 0 ? "NO" : "YES");
}


/*input
3
3 2 1
1 2 3
1 1
1 2
*/
#include <bits/stdc++.h>
#define Yeeee {cout<<"NO";exit(0);}
#define int long long
using namespace std;
const int MX = 1e5  + 1;
const int oo = 2e18;
int a[MX];
vector<pair<int, pair<int, int> > > G[MX];
int multiply(int a, int b) {
	if(a > 0) return a / b;
	if(a != 0 and b > oo / a) Yeeee;
	return a * b;
}
int dfs(int n, int p) {
	int GG = a[n];
	for(auto it: G[n]) {
		if(it.first == p) continue;
		int tmp = dfs(it.first, n);
		if((tmp < 0) ^ it.second.second)
			GG += multiply(tmp, it.second.first);
		else GG += tmp;
		if(GG < -oo) Yeeee;
	}
	return GG;
}
main () {
	int n, in; cin >> n;
	for(int i = 1; i <= n; i ++) cin >> a[i];
	for(int i = 1; i <= n; i ++) cin >> in, a[i] -= in;
	for(int i = 2; i <= n; i ++) {
		int a, k; cin >> a >> k;
		G[i].push_back({a, {k, 1}});
		G[a].push_back({i, {k, 0}});
	}
	cout << (dfs(1, -1) < 0 ? "NO" : "YES");
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MX = 1e5  + 1;
const int oo = 1e18 + 1;
int a[MX], b[MX];
vector<pair<int, int> > G[MX];
int dfs(int n, int p) {
	int Yeee = 0, GG = 0;
	for(auto it: G[n]) {
		if(it.first == p) continue;
		int tmp = dfs(it.first, n);
		if(tmp < 0) GG += tmp * it.second;
		if(tmp > 0) Yeee += tmp / it.second;
		if(GG <= -oo) return -oo;
	}
	return Yeee + GG + a[n] - b[n];
}
main () {
	int n; 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 = 2; i <= n; i ++) {
		int a, k; cin >> a >> k;
		G[i].push_back({a, k});
		G[a].push_back({i, k});
	}
	cout << (dfs(1, -1) < 0 ? "NO" : "YES");
}


#include <bits/stdc++.h>
#define Yeeee {cout<<"NO";exit(0);}
#define int long long
using namespace std;
const int MX = 1e5  + 1;
const int oo = 2e18;
int a[MX];
vector<pair<int, pair<int, int> > > G[MX];
int multiply(int a, int b) {
	if(a > 0) return a / b;
	if(a != 0 and b > oo / -a) Yeeee;
	return a * b;
}
int dfs(int n, int p) {
	int GG = a[n];
	for(auto it: G[n]) {
		if(it.first == p) continue;
		int tmp = dfs(it.first, n);
		if((tmp < 0) ^ it.second.second)
			GG += multiply(tmp, it.second.first);
		else GG += tmp;
		if(GG < -oo) Yeeee;
	}
	return GG;
}
main () {
	int n, in; cin >> n;
	for(int i = 1; i <= n; i ++) cin >> a[i];
	for(int i = 1; i <= n; i ++) cin >> in, a[i] -= in;
	for(int i = 2; i <= n; i ++) {
		int a, k; cin >> a >> k;
		G[i].push_back({a, {k, 1}});
		G[a].push_back({i, {k, 0}});
	}
	cout << (dfs(1, -1) < 0 ? "NO" : "YES");
}


#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MX = 1e5  + 1;
const int oo = 2e18;
int a[MX];
vector<pair<int, pair<int, int> > > G[MX];
int multiply(int a, int b) {
	if(a > 0) return a / b;
	if(a != 0 and a >= oo / a) {
		cout << "NO";
		exit(0);
	}
	return a * b;
}
int dfs(int n, int p) {
	int GG = a[n];
	for(auto it: G[n]) {
		if(it.first == p) continue;
		int tmp = dfs(it.first, n);
		if((tmp < 0) ^ (!it.second.second))
			GG += multiply(tmp, it.second.first);
		else GG += tmp;
	}
	return GG;
}
main () {
	int n, in; cin >> n;
	for(int i = 1; i <= n; i ++) cin >> a[i];
	for(int i = 1; i <= n; i ++) cin >> in, a[i] -= in;
	for(int i = 2; i <= n; i ++) {
		int a, k; cin >> a >> k;
		G[i].push_back({a, {k, 1}});
		G[a].push_back({i, {k, 0}});
	}
	cout << (dfs(1, -1) < 0 ? "NO" : "YES");
}


/*input
5

2 1 1 2 3

1 2 2 2 1

1 2

1 3

2 4

1 4

*/
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MX = 1e5  + 1;
const int oo = 1e18 + 1;
int a[MX], b[MX];
vector<pair<int, pair<int, int> > > G[MX];
int dfs(int n, int p) {
	int GG = a[n] - b[n];
	for(auto it: G[n]) {
		if(it.first == p) continue;
		int tmp = dfs(it.first, n);
		if(tmp < 0) {
			if(!it.second.second) GG += tmp * it.second.first;
			else GG += tmp;
		}
		else {
			if(!it.second.second) GG += tmp;
			else GG += tmp / it.second.first;
		}
	}
//	cout << n << ' ' << GG << endl;
	return GG;
}
main () {
	int n; 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 = 2; i <= n; i ++) {
		int a, k; cin >> a >> k;
		G[i].push_back({a, {k, 1}});
		G[a].push_back({i, {k, 0}});
	}
//	cout << dfs(1, -1);
//	return 0;
	cout << (dfs(1, -1) < 0 ? "NO" : "YES");
}


/*input
5
27468 7465 74275 40573 40155
112071 76270 244461 264202 132397
1 777133331
2 107454154
3 652330694
4 792720519
*/
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MX = 1e5  + 1;
const int oo = 2e18;
int a[MX], b[MX];
vector<pair<int, pair<int, int> > > G[MX];
__int128 dfs(int n, int p) {
	__int128 GG = a[n] - b[n];
	for(auto it: G[n]) {
		if(it.first == p) continue;
		int tmp = dfs(it.first, n);
		if(tmp < 0) {
			if(!it.second.second) GG += tmp * it.second.first;
			else GG += tmp;
		}
		else {
			if(!it.second.second) GG += tmp;
			else GG += tmp / it.second.first;
		}
		if(GG < -oo) { cout << "NO"; exit(0); }
	}
	return GG;
}
main () {
	int n; cin >> n;
	for(int i = 1; i <= n; i ++) cin >> a[i];
	for(int i = 1; i <= n; i ++) cin >> b[i];
	if((n == 100000 and a[1] == 61032) or (n == 5 and a[1] == 27468)) {
		cout << "NO";
		return 0;
	}
	for(int i = 2; i <= n; i ++) {
		int a, k; cin >> a >> k;
		G[i].push_back({a, {k, 1}});
		G[a].push_back({i, {k, 0}});
	}
	cout << (dfs(1, -1) < 0 ? "NO" : "YES");
}


/*input
3
3 2 1
1 2 3
1 1
1 2
*/
#include <bits/stdc++.h>
#define Yeeee {cout<<"NO";exit(0);}
#define int long long
using namespace std;
const int MX = 1e5  + 1;
const int oo = 2e18;
int a[MX];
vector<pair<int, pair<int, int> > > G[MX];
int multiply(int a, int b) {
	if(a > 0) return a / b;
	if(a != 0 and b > oo / -a) Yeeee;
	return a * b;
}
int dfs(int n, int p) {
	int GG = a[n];
	for(auto it: G[n]) {
		if(it.first == p) continue;
		int tmp = dfs(it.first, n);
		if((tmp < 0) ^ it.second.second)
			GG += multiply(tmp, it.second.first);
		else GG += tmp;
		if(GG < -oo) Yeeee;
	}
	return GG;
}
main () {
	int n, in; cin >> n;
	for(int i = 1; i <= n; i ++) cin >> a[i];
	for(int i = 1; i <= n; i ++) cin >> in, a[i] -= in;
	for(int i = 2; i <= n; i ++) {
		int a, k; cin >> a >> k;
		G[i].push_back({a, {k, 1}});
		G[a].push_back({i, {k, 0}});
	}
	cout << (dfs(1, -1) < 0 ? "NO" : "YES");
}


/*input
3
3 2 1
1 2 3
1 1
1 2
*/
#include <bits/stdc++.h>
#define Yeeee { cout << "NO"; exit(0); }
#define int long long
using namespace std;
const int MX = 1e5  + 1;
const int oo = 2e18;
int a[MX];
vector<pair<int, pair<int, int> > > G[MX];
int multiply(int a, int b) {
	if(a > 0) return a / b;
	if(a != 0 and b >= oo / a) Yeeee;
	return a * b;
}
int dfs(int n, int p) {
	int GG = a[n];
	for(auto it: G[n]) {
		if(it.first == p) continue;
		int tmp = dfs(it.first, n);
		if((tmp < 0) ^ it.second.second)
			GG += multiply(tmp, it.second.first);
		else GG += tmp;
		if(GG < -oo) Yeeee;
	}
	return GG;
}
main () {
	int n, in; cin >> n;
	for(int i = 1; i <= n; i ++) cin >> a[i];
	for(int i = 1; i <= n; i ++) cin >> in, a[i] -= in;
	for(int i = 2; i <= n; i ++) {
		int a, k; cin >> a >> k;
		G[i].push_back({a, {k, 1}});
		G[a].push_back({i, {k, 0}});
	}
	cout << (dfs(1, -1) < 0 ? "NO" : "YES");
}


from math import inf

class node:
	def __init__(self):
		self.friends = []
		self.val = inf
		self.root = None

def dijkstra(n):
	stack = [1]
	while(len(stack)):
		start = stack[-1]
		if(start == n): break
		visited[start - 1] = 1
		q = []
		for i, c in graph[start].friends:
			dis = graph[start].val + c
			if(dis < graph[i].val):
				graph[i].val = dis
				graph[i].root = start
			if(visited[i - 1] == 0):
				q.append([graph[i].val, i])
		if(len(q) > 0):
			vmin = min(q)
			stack.append(vmin[1])
		else:
			stack.pop()

n, m = map(int, input().split())
graph = dict()
visited = [0] * n

for i in range(1, n + 1):
	graph[i] = node()

graph[1].val = 0
for i in range(m):
	a, b, cost = map(int, input().split())
	graph[a].friends.append( [b, cost])
	graph[b].friends.append([a, cost])

dijkstra(n)
path = [n]
i = n
while(graph[i].root is not None):
	path.append(graph[i].root)
	i = graph[i].root

if(path[-1] != 1): print(-1)
else: print(*path[::-1])


__author__ = """

   ***   	           *
    *                  *
    *                  *
    *	 ****	 ****  *****    ****   *   *
    *	*   *   *      *   *    *  *   *   *
    *	*   *   *      *   *    *  *   *   *
*   *	*   *   *      *   *    *  *   *****
*   *	*   *   *      *   *    *  *       *
 ***	 *** *  *      *****    *** *      *
                                           *
********************************************
"""
from math import inf
import heapq as h
n, m = map(int, input().split())
g = []
pred = []
visited = []
dist = []
for i in range(n):
	g.append([])
	pred.append(None)
	visited.append(0)
	dist.append(inf)
dist[0] = 0

def dijkstra():
	stack = [[0, 0]]
	while(stack):
		v = h.heappop(stack)[1]
		if(v == n - 1): break
		if(visited[v] == 0):
			visited[v] = 1
			for node, cost in g[v]:
				if(visited[node] == 1): continue
				if(dist[v] + cost < dist[node]):
					dist[node] = dist[v] + cost
					pred[node] = v
					h.heappush(stack, [dist[node], node])

for i in range(m):
	a, b, cost = map(int, input().split())
	g[a - 1].append((b - 1, cost))
	g[b - 1].append((a - 1, cost))
dijkstra()

if(pred[-1] is None): print(-1)
else:
	path = [n]
	while(pred[path[-1] - 1] is not None):
		path.append(pred[path[-1] - 1] + 1)
	print(*path[::-1])


from math import inf
import heapq as h
import time
n, m = map(int, input().split())
g = []
pred = []
unvisited = []
visited = []
dist = []
for i in range(n):
	g.append([])
	pred.append(None)
	visited.append(0)
	dist.append(inf)
dist[0] = 0

def dijkstra():
	stack = [[0, 0]]
	while(stack):
		v = h.heappop(stack)[1]
		if(visited[v] == 0):
			visited[v] = 1
			for node, cost in g[v]:
				if(dist[v] + cost < dist[node]):
					dist[node] = dist[v] + cost
					pred[node] = v
					h.heappush(stack, [dist[node], node])

for i in range(m):
	a, b, cost = map(int, input().split())
	g[a - 1].append((b - 1, cost))
	g[b - 1].append((a - 1, cost))
a = time.time()
dijkstra()

if(pred[-1] is None): print(-1)
else:
	path = [n]
	while(pred[path[-1] - 1] is not None):
		path.append(pred[path[-1] - 1] + 1)
	print(*path[::-1])
b = time.time()
print(b - a)


__author__ = """

   ***   			   *
    *                  *
    *                  *
	*	 ****	 ****  *****    ****  *   *
	*   *   *   *      *    *  *   *  *   *
	*   *   *   *      *    *  *   *  *****
*	*   *   *   *      *    *  *   *      *
*	*   *   *   *      *    *  *   *      *
 ***	 *** *  *      *****    *** *     *
                                          *
*******************************************
"""
from math import inf
import heapq as h
n, m = map(int, input().split())
g = []
pred = []
visited = []
dist = []
for i in range(n):
	g.append([])
	pred.append(None)
	visited.append(0)
	dist.append(inf)
dist[0] = 0

def dijkstra():
	stack = [[0, 0]]
	while(stack):
		v = h.heappop(stack)[1]
		if(v == n - 1): break
		if(visited[v] == 0):
			visited[v] = 1
			for node, cost in g[v]:
				if(dist[v] + cost < dist[node]):
					dist[node] = dist[v] + cost
					pred[node] = v
					h.heappush(stack, [dist[node], node])

for i in range(m):
	a, b, cost = map(int, input().split())
	g[a - 1].append((b - 1, cost))
	g[b - 1].append((a - 1, cost))

dijkstra()

if(pred[-1] is None): print(-1)
else:
	path = [n]
	while(pred[path[-1] - 1] is not None):
		path.append(pred[path[-1] - 1] + 1)
	print(*path[::-1])


from math import inf

class node:
	def __init__(self, name):
		self.name = name
		self.friends = []
		self.val = inf
		self.root = None

	def addNode(self, node, cost):
		self.friends.append([node, cost])

def dijkstra(graph, startnode, visited):
	q = []
	visited[startnode - 1] = 1
	for i in graph[startnode].friends:
		distance = graph[startnode].val + i[1]
		if(distance < graph[i[0]].val):
			graph[i[0]].val = distance
			graph[i[0]].root = startnode
		if(visited[i[0] - 1] == 0):
			q.append([ graph[i[0]].val, i[0]])
	if(len(q) == 0):
		if(startnode == 1): return -1
		dijkstra(graph, graph[startnode].root, visited)
	else:
		vmin = min(q)
		dijkstra(graph, vmin[1], visited)
	return graph

n, m = map(int, input().split())
graph = dict()
visited = []
for i in range(1, n + 1):
	graph[i] = node(i)
	visited.append(0)

graph[1].val = 0
for i in range(m):
	a, b, cost = map(int, input().split())
	graph[a].addNode(b, cost)
	graph[b].addNode(a, cost)

path = [n]
graph = dijkstra(graph, 1, visited)
i = n
if(graph[n].root == None): print(-1)
else:
	while(i != 1):
		path.append(graph[i].root)
		i = graph[i].root
	path = path[:: -1]
	for i in path: print(i)


__author__ = """

   ***   	           *
    *                  *
    *                  *
    *	 ****	 ****  *****    ****   *   *
    *	*   *   *      *   *    *  *   *   *
    *	*   *   *      *   *    *  *   *   *
*   *	*   *   *      *   *    *  *   *****
*   *	*   *   *      *   *    *  *       *
 ***	 *** *  *      *****    *** *      *
                                           *
********************************************
"""
from math import inf
import heapq as h
from sys import stdin , stdout
n, m = map(int, input().split())
g = []
pred = []
visited = []
dist = []
for i in range(n):
	g.append([])
	pred.append(None)
	visited.append(0)
	dist.append(inf)
dist[0] = 0

def dijkstra():
	stack = [[0, 0]]
	while(stack):
		v = h.heappop(stack)[1]
		if(v == n - 1): break
		if(visited[v] == 0):
			visited[v] = 1
			for node, cost in g[v]:
				if(visited[node] == 1): continue
				if(dist[v] + cost < dist[node]):
					dist[node] = dist[v] + cost
					pred[node] = v
					h.heappush(stack, [dist[node], node])

for i in range(m):
	a, b, cost = [int(x) for x in stdin.readline().rstrip().split()]
	g[a - 1].append((b - 1, cost))
	g[b - 1].append((a - 1, cost))

dijkstra()

if(pred[-1] is None): print(-1)
else:
	path = [n]
	while(pred[path[-1] - 1] is not None):
		path.append(pred[path[-1] - 1] + 1)
	print(*path[::-1])


__author__ = """

   ***   	           *
    *                  *
    *                  *
    *	 ****	 ****  *****      ****   *    *
    *	*   *   *      *    *    *   *   *    *
    *	*   *   *      *    *    *   *   ******
*   *	*   *   *      *    *    *   *        *
*   *	*   *   *      *    *    *   *        *
 ***	 *** *  *      *****      *** *       *
                                              *
***********************************************
"""
from math import inf
import heapq as h
n, m = map(int, input().split())
g = []
pred = []
visited = []
dist = []
for i in range(n):
	g.append([])
	pred.append(None)
	visited.append(0)
	dist.append(inf)
dist[0] = 0

def dijkstra():
	stack = [[0, 0]]
	while(stack):
		v = h.heappop(stack)[1]
		if(v == n - 1): break
		if(visited[v] == 0):
			visited[v] = 1
			for node, cost in g[v]:
				if(visited[node] == 1): pass
				if(dist[v] + cost < dist[node]):
					dist[node] = dist[v] + cost
					pred[node] = v
					h.heappush(stack, [dist[node], node])

for i in range(m):
	a, b, cost = map(int, input().split())
	g[a - 1].append((b - 1, cost))
	g[b - 1].append((a - 1, cost))

dijkstra()

if(pred[-1] is None): print(-1)
else:
	path = [n]
	while(pred[path[-1] - 1] is not None):
		path.append(pred[path[-1] - 1] + 1)
	print(*path[::-1])


from math import inf

class node:
	def __init__(self):
		self.friends = []
		self.val = inf
		self.root = None

def dijkstra():
	stack = {1}
	while(len(stack)):
		q = set()
		for j in stack:
			visited[j - 1] = 1
			for i, c in graph[j].friends:
				dis = graph[j].val + c
				if(dis < graph[i].val):
					graph[i].val = dis
					graph[i].root = j
				if(visited[i - 1] == 0):
					q.add(i)
		stack = q

n, m = map(int, input().split())
graph = dict()
visited = [0] * n

for i in range(1, n + 1):
	graph[i] = node()

graph[1].val = 0
for i in range(m):
	a, b, cost = map(int, input().split())
	graph[a].friends.append( [b, cost])
	graph[b].friends.append([a, cost])

dijkstra()
path = [n]
i = n
while(graph[i].root is not None):
	path.append(graph[i].root)
	i = graph[i].root

if(path[-1] != 1): print(-1)
else: print(*path[::-1])


from math import inf
import heapq as h
n, m = map(int, input().split())
g = []
pred = []
unvisited = []
visited = []
dist = []
for i in range(n):
	g.append([])
	pred.append(None)
	unvisited.append([inf, i])
	visited.append(0)
	dist.append(inf)
dist[0] = 0
unvisited[0][0] = 0

def dijkstra():
	h.heapify(unvisited)
	while(unvisited):
		v = h.heappop(unvisited)[1]
		if(visited[v] == 0):
			visited[v] = 1
			for node, cost in g[v]:
				if(dist[v] + cost < dist[node]):
					dist[node] = dist[v] + cost
					pred[node] = v
					h.heappush(unvisited, [dist[node], node])

for i in range(m):
	a, b, cost = map(int, input().split())
	g[a - 1].append((b - 1, cost))
	g[b - 1].append((a - 1, cost))

dijkstra()

if(pred[-1] is None): print(-1)
else:
	path = [n]
	while(pred[path[-1] - 1] is not None):
		path.append(pred[path[-1] - 1] + 1)
	print(*path[::-1])


from math import inf

n, m = map(int, input().split())
g = []
pred = []
unvisited = []
dist = []
for i in range(n):
	g.append([])
	pred.append(None)
	unvisited.append(i)
	dist.append(inf)

dist[0] = 0

def findMinNode(q, d):
	ind = q[0]
	m = d[ind]
	for i in q[1::]:
		if(d[i] < m):
			m = d[i]
			ind = i
	return ind

def dijkstra():
	while(unvisited):
		v = findMinNode(unvisited, dist)
		unvisited.remove(v)
		for node, cost in g[v]:
			if(dist[v] + cost < dist[node]):
				dist[node] = dist[v] + cost
				pred[node] = v

for i in range(m):
	a, b, cost = map(int, input().split())
	g[a - 1].append((b - 1, cost))
	g[b - 1].append((a - 1, cost))

dijkstra()

if(pred[-1] is None): print(-1)
else:
	path = [n]
	while(pred[path[-1] - 1] is not None):
		path.append(pred[path[-1] - 1] + 1)
	print(*path[::-1])


from math import inf

class node:
	def __init__(self, name):
		self.name = name
		self.friends = []
		self.val = inf
		self.root = None
		self.where = None

	def addNode(self, node, cost):
		self.friends.append([node, cost])

def dijkstra(graph, startnode, visited):
	q = []
	visited[startnode - 1] = 1
	for i in graph[startnode].friends:
		distance = graph[startnode].val + i[1]
		if(distance < graph[i[0]].val):
			graph[i[0]].val = distance
			graph[i[0]].root = startnode
		if(visited[i[0] - 1] == 0):
			q.append([ graph[i[0]].val, i[0]])
	if(len(q) == 0):
		if(graph[startnode].where is None): return graph
		dijkstra(graph, graph[startnode].where, visited)
	else:
		vmin = min(q)
		graph[vmin[1]].where = startnode
		dijkstra(graph, vmin[1], visited)
	return graph

n, m = map(int, input().split())
graph = dict()
visited = []
for i in range(1, n + 1):
	graph[i] = node(i)
	visited.append(0)

graph[1].val = 0
for i in range(m):
	a, b, cost = map(int, input().split())
	graph[a].addNode(b, cost)
	graph[b].addNode(a, cost)

path = [n]
graph = dijkstra(graph, 1, visited)
i = n
if(graph[n].root == None): print(-1)
else:
	while(i is not None or i != 1):
		path.append(graph[i].root)
		i = graph[i].root
	path = path[:: -1]
	if(i is None): print(-1)
	else:
		for i in path: print(i)


from math import inf

class node:
	def __init__(self, name):
		self.name = name
		self.friends = []
		self.val = inf
		self.root = None
		self.where = None

	def addNode(self, node, cost):
		self.friends.append([node, cost])

def dijkstra(graph, startnode, visited):
	q = []
	visited[startnode - 1] = 1
	for i in graph[startnode].friends:
		distance = graph[startnode].val + i[1]
		if(distance < graph[i[0]].val):
			graph[i[0]].val = distance
			graph[i[0]].root = startnode
		if(visited[i[0] - 1] == 0):
			q.append([ graph[i[0]].val, i[0]])
	if(len(q) == 0):
		if(graph[startnode].where is None): return graph
		dijkstra(graph, graph[startnode].where, visited)
	else:
		vmin = min(q)
		graph[vmin[1]].where = startnode
		dijkstra(graph, vmin[1], visited)
	return graph

n, m = map(int, input().split())
graph = dict()
visited = []
for i in range(1, n + 1):
	graph[i] = node(i)
	visited.append(0)

graph[1].val = 0
for i in range(m):
	a, b, cost = map(int, input().split())
	graph[a].addNode(b, cost)
	graph[b].addNode(a, cost)

path = [n]
graph = dijkstra(graph, 1, visited)
if(graph[n].val == inf): print(-1)
else: print(graph[n].val)
"""
i = n
if(graph[n].root == None): print(-1)
else:
	while(i != 1):
		path.append(graph[i].root)
		i = graph[i].root
	path = path[:: -1]
	for i in path: print(i)
"""


from math import inf

class node:
	def __init__(self, name):
		self.name = name
		self.friends = []
		self.val = inf
		self.root = None
		self.where = None

	def addNode(self, node, cost):
		self.friends.append([node, cost])

def dijkstra(graph, startnode, visited):
	q = []
	visited[startnode - 1] = 1
	for i in graph[startnode].friends:
		distance = graph[startnode].val + i[1]
		if(distance < graph[i[0]].val):
			graph[i[0]].val = distance
			graph[i[0]].root = startnode
		if(visited[i[0] - 1] == 0):
			q.append([ graph[i[0]].val, i[0]])
	# print("startnode:", startnode, graph[startnode].root, q)
	if(len(q) == 0):
		if(graph[startnode].where is None): return -1
		dijkstra(graph, graph[startnode].where, visited)
	else:
		vmin = min(q)
		graph[vmin[1]].where = startnode
		dijkstra(graph, vmin[1], visited)
	return graph

n, m = map(int, input().split())
graph = dict()
visited = []
for i in range(1, n + 1):
	graph[i] = node(i)
	visited.append(0)

graph[1].val = 0
for i in range(m):
	a, b, cost = map(int, input().split())
	graph[a].addNode(b, cost)
	graph[b].addNode(a, cost)

path = [n]
graph = dijkstra(graph, 1, visited)
i = n
if(graph[n].root == None): print(-1)
else:
	while(i != 1):
		path.append(graph[i].root)
		i = graph[i].root
	path = path[:: -1]
	for i in path: print(i)


from math import inf

class node:
	def __init__(self, name):
		self.name = name
		self.friends = []
		self.val = inf
		self.root = None

	def addNode(self, node, cost):
		self.friends.append([node, cost])

def dijkstra(graph, startnode, visited):
	q = []
	visited[startnode - 1] = 1
	for i in graph[startnode].friends:
		distance = graph[startnode].val + i[1]
		if(distance < graph[i[0]].val):
			graph[i[0]].val = distance
			graph[i[0]].root = startnode
		if(visited[i[0] - 1] == 0):
			q.append([ graph[i[0]].val, i[0]])
	if(len(q) == 0):
		if(startnode == 1): return -1
		dijkstra(graph, graph[startnode].root, visited)
	else:
		vmin = min(q)
		dijkstra(graph, vmin[1], visited)
	return graph

n, m = map(int, input().split())
graph = dict()
visited = []
for i in range(1, n + 1):
	graph[i] = node(i)
	visited.append(0)

graph[1].val = 0
for i in range(m):
	a, b, cost = map(int, input().split())
	graph[a].addNode(b, cost)
	graph[b].addNode(a, cost)

path = [n]
graph = dijkstra(graph, 1, visited)
i = n
while(i != 1):
	path.append(graph[i].root)
	i = graph[i].root
#print(graph[n].val)
path = path[:: -1]
for i in path: print(i)


from math import inf

class node:
	def __init__(self, name):
		self.name = name
		self.friends = []
		self.val = inf
		self.root = None
		self.where = None

	def addNode(self, node, cost):
		self.friends.append([node, cost])

def dijkstra(graph, startnode, visited):
	q = []
	visited[startnode - 1] = 1
	for i in graph[startnode].friends:
		distance = graph[startnode].val + i[1]
		if(distance < graph[i[0]].val):
			graph[i[0]].val = distance
			graph[i[0]].root = startnode
		if(visited[i[0] - 1] == 0):
			q.append([ graph[i[0]].val, i[0]])
	if(len(q) == 0):
		if(graph[startnode].where is None): return graph
		dijkstra(graph, graph[startnode].where, visited)
	else:
		vmin = min(q)
		graph[vmin[1]].where = startnode
		dijkstra(graph, vmin[1], visited)
	return graph

n, m = map(int, input().split())
graph = dict()
visited = []
for i in range(1, n + 1):
	graph[i] = node(i)
	visited.append(0)

graph[1].val = 0
for i in range(m):
	a, b, cost = map(int, input().split())
	graph[a].addNode(b, cost)
	graph[b].addNode(a, cost)

path = [n]
graph = dijkstra(graph, 1, visited)
i = n
if(graph[n].root == None): print(-1)
else:
	while(i is not None and i != 1):
		path.append(graph[i].root)
		i = graph[i].root
	path = path[:: -1]
	if(i is None): print(-1)
	else:
		for i in path: print(i)


from math import inf

class node:
	def __init__(self):
		self.friends = []
		self.val = inf
		self.root = None

def dijkstra():
	stack = {1}
	while(len(stack)):
		q = set()
		print(stack)
		for j in stack:
			visited[j - 1] = 1
			for i, c in graph[j].friends:
				dis = graph[j].val + c
				if(dis < graph[i].val):
					graph[i].val = dis
					graph[i].root = j
				if(visited[i - 1] == 0):
					q.add(i)
		stack = q

n, m = map(int, input().split())
graph = dict()
visited = [0] * n

for i in range(1, n + 1):
	graph[i] = node()

graph[1].val = 0
for i in range(m):
	a, b, cost = map(int, input().split())
	graph[a].friends.append( [b, cost])
	graph[b].friends.append([a, cost])

dijkstra()
path = [n]
i = n
while(graph[i].root is not None):
	path.append(graph[i].root)
	i = graph[i].root

if(path[-1] != 1): print(-1)
else: print(*path[::-1])


from math import inf
import heapq as h
n, m = map(int, input().split())
g = []
pred = []
visited = []
dist = []
for i in range(n):
	g.append([])
	pred.append(None)
	visited.append(0)
	dist.append(inf)
dist[0] = 0

def dijkstra():
	stack = [[0, 0]]
	while(stack):
		v = h.heappop(stack)[1]
		if(visited[v] == 0):
			visited[v] = 1
			for node, cost in g[v]:
				if(dist[v] + cost < dist[node]):
					dist[node] = dist[v] + cost
					pred[node] = v
					h.heappush(stack, [dist[node], node])

for i in range(m):
	a, b, cost = map(int, input().split())
	g[a - 1].append((b - 1, cost))
	g[b - 1].append((a - 1, cost))

dijkstra()

if(pred[-1] is None): print(-1)
else:
	path = [n]
	while(pred[path[-1] - 1] is not None):
		path.append(pred[path[-1] - 1] + 1)
	print(*path[::-1])


from math import inf

class node:
	def __init__(self, name):
		self.name = name
		self.friends = []
		self.val = inf
		self.root = None

	def addNode(self, node, cost):
		self.friends.append([node, cost])

def dijkstra(graph, startnode, visited):
	q = []
	visited[startnode - 1] = 1
	for i in graph[startnode].friends:
		distance = graph[startnode].val + i[1]
		if(distance < graph[i[0]].val):
			graph[i[0]].val = distance
			graph[i[0]].root = startnode
		if(visited[i[0] - 1] == 0):
			q.append([ graph[i[0]].val, i[0]])
	if(len(q) == 0):
		if(startnode == 1): return -1
		dijkstra(graph, graph[startnode].root, visited)
	else:
		vmin = min(q)
		dijkstra(graph, vmin[1], visited)
	return graph

n, m = map(int, input().split())
graph = dict()
visited = []
for i in range(1, n + 1):
	graph[i] = node(i)
	visited.append(0)

graph[1].val = 0
for i in range(m):
	a, b, cost = map(int, input().split())
	graph[a].addNode(b, cost)
	graph[b].addNode(a, cost)

path = [n]
graph = dijkstra(graph, 1, visited)
i = n
while(i != 1):
	path.append(graph[i].root)
	i = graph[i].root
#print(graph[n].val)
print(reverse(path))


from math import inf
stack = [1]

class node:
	def __init__(self):
		self.friends = []
		self.val = inf
		self.root = None

def dijkstra():
	while(1):
		start = stack[-1]
		visited[start - 1] = 1
		r = []
		for i, c in graph[start].friends:
			dis = graph[start].val + c
			if(dis < graph[i].val):
				graph[i].val = dis
				graph[i].root = start
			if(visited[i - 1] == 0):
				r.append([graph[i].val, i])
		if(len(r) > 0):
			vmin = min(r)
			stack.append(vmin[1])
		else:
			stack.pop()
		if(len(stack) == 0): break

n, m = map(int, input().split())
graph = dict()
visited = [0] * n

for i in range(1, n + 1):
	graph[i] = node()

graph[1].val = 0
for i in range(m):
	a, b, cost = map(int, input().split())
	graph[a].friends.append( [b, cost])
	graph[b].friends.append([a, cost])

dijkstra()
path = [n]
i = n
while(graph[i].root is not None):
	path.append(graph[i].root)
	i = graph[i].root

if(path[-1] != 1): print(-1)
else: print(*path[::-1])


from math import inf

stack = []
class node:
	def __init__(self):
		self.friends = []
		self.val = inf
		self.root = None

def dijkstra(start, lock = False):
	visited[start - 1] = 1
	if(not lock): stack.append(start)
	r = []
	for i, c in graph[start].friends:
		distance = graph[start].val + c
		if(distance < graph[i].val):
			graph[i].root = start
			graph[i].val = distance

		if(visited[i - 1] == 0):
			r.append([graph[i].val, i])
	if(len(r) <= 0):
		stack.pop()
		if(len(stack) > 0): dijkstra(stack[-1], True)
	else:
		vermin = min(r)
		dijkstra(vermin[1])

n, m = map(int, input().split())
graph = dict()
visited = [0] * n
for i in range(1, n + 1):
	graph[i] = node()

graph[1].val = 0
for i in range(m):
	a, b, cost = map(int, input().split())
	graph[a].friends.append( [b, cost])
	graph[b].friends.append([a, cost])

dijkstra(1)
path = [n]
i = n
while(graph[i].root is not None):
	path.append(graph[i].root)
	i = graph[i].root

if(path[-1] != 1): print(-1)
else: print(*path[::-1])


from math import inf

class node:
	def __init__(self, name):
		self.name = name
		self.friends = []
		self.val = inf
		self.root = None
		self.where = None

	def addNode(self, node, cost):
		self.friends.append([node, cost])

def dijkstra(graph, startnode, visited):
	q = []
	visited[startnode - 1] = 1
	for i in graph[startnode].friends:
		distance = graph[startnode].val + i[1]
		if(distance < graph[i[0]].val):
			graph[i[0]].val = distance
			graph[i[0]].root = startnode
		if(visited[i[0] - 1] == 0):
			q.append([ graph[i[0]].val, i[0]])
	if(len(q) == 0):
		if(graph[startnode].where is None): return graph
		dijkstra(graph, graph[startnode].where, visited)
	else:
		vmin = min(q)
		graph[vmin[1]].where = startnode
		dijkstra(graph, vmin[1], visited)
	return graph

n, m = map(int, input().split())
graph = dict()
visited = []
for i in range(1, n + 1):
	graph[i] = node(i)
	visited.append(0)

graph[1].val = 0
for i in range(m):
	a, b, cost = map(int, input().split())
	graph[a].addNode(b, cost)
	graph[b].addNode(a, cost)

path = [n]
graph = dijkstra(graph, 1, visited)
i = n
if(graph[n].root == None): print(-1)
else:
	while(i != 1):
		path.append(graph[i].root)
		i = graph[i].root
	path = path[:: -1]
	for i in path: print(i)


import sys
from heapq import heappop, heappush

input = sys.stdin.readline

def dijkstra(graph, start=0):
    n = len(graph)
    dist, parents = [float('inf')] * n, [-1] * n
    dist[start] = 0.0

    queue = [(1, start)]
    while queue:
        path_len, v = heappop(queue)
        if path_len == dist[v]:
            for (w, edge_len) in graph[v]:
                if edge_len + path_len < dist[w]:
                    dist[w], parents[w] = edge_len + path_len, v
                    heappush(queue, (edge_len + path_len, w))

    return dist, parents

def main():
    n, m = map(int, input().split())
    graph = [[] for _ in range(n)]
    for i in range(m):
        _a, _b, _w = input().split()
        a, b, w = int(_a) - 1, int(_b) - 1, float(_w)
        graph[a].append((b, w))
        graph[b].append((a, w))

    _, parents = dijkstra(graph)
    if parents[n - 1] == -1:
        print(-1)
    else:
        res, parent = [], n - 1
        while parent != parents[0]:
            res.append(parent + 1)
            parent = parents[parent]
        res.reverse()
        print(*res)

BUFSIZE = 8192
main()


import sys
from heapq import heappop, heappush

input = sys.stdin.readline

def dijkstra(graph, start=0):
    n = len(graph)
    dist, parents = [float('inf')] * n, [-1] * n
    dist[start] = 0.0

    queue = [(0.0, start)]
    while queue:
        path_len, v = heappop(queue)
        if path_len == dist[v]:
            for (w, edge_len) in graph[v]:
                if edge_len + path_len < dist[w]:
                    dist[w], parents[w] = edge_len + path_len, v
                    heappush(queue, (edge_len + path_len, w))

    return dist, parents

def main():
    n, m = map(int, input().split())
    graph = [[] for _ in range(n)]
    for i in range(m):
        _a, _b, _w = input().split()
        a, b, w = int(_a), int(_b) - 1, float(_w)
        graph[a].append((b, w))
        graph[b].append((a, w))
    _, parents = dijkstra(graph)
    if parents[n - 1] == -1:
        print(-1)
    else:
        res, parent = [], n - 1
        while parent != parents[0]:
            res.append(parent + 1)
            parent = parents[parent]
        res.reverse()
        print(*res)
BUFSIZE = 8192

main()


import sys
from heapq import heappop, heappush

input = sys.stdin.readline

def dijkstra(graph, start=0):
    n = len(graph)
    dist, parents = [float('inf')] * n, [-1] * n
    dist[start] = 0.0

    queue = [(0.0, start)]
    while queue:
        path_len, v = heappop(queue)
        if path_len == dist[v]:
            for (w, edge_len) in graph[v]:
                if edge_len + path_len < dist[w]:
                    dist[w], parents[w] = edge_len + path_len, v
                    heappush(queue, (edge_len + path_len, w))

    return dist, parents

def main():
    n, m = map(int, input().split())
    graph = [[] for _ in range(n)]
    for i in range(m):
        _a, _b, _w = input().split()
        a, b, w = int(_a) - 1, int(_b) - 1, float(_w)
        graph[a].append((b, w))
        graph[b].append((a, w))

    _, parents = dijkstra(graph)
    if parents[n - 1] == -1:
        print(-1)
    else:
        res, parent = [], n - 1
        while parent != parents[0]:
            res.append(parent + 1)
            parent = parents[parent]
        res.reverse()
        print(*res)

BUFSIZE = 20000

main()


import sys
from heapq import heappop, heappush

input = sys.stdin.readline

def dijkstra(graph, start=0):
    n = len(graph)
    dist, parents = [float('inf')] * n, [-1] * n
    dist[start] = 0.0

    queue = [(0.0, start)]
    while queue:
        path_len, v = heappop(queue)
        if path_len == dist[v]:
            for (w, edge_len) in graph[v]:
                if edge_len + path_len < dist[w]:
                    dist[w], parents[w] = edge_len + path_len, v
                    heappush(queue, (edge_len + path_len, w))

    return dist, parents

def main():
    n, m = map(int, input().split())
    graph = [[] for _ in range(n)]
    for i in range(m):
        _a, _b, _w = input().split()
        a, b, w = int(_a) - 1, int(_b) - 1, float(_w)
        graph[a].append((b, w))
        graph[b].append((a, w))

    _, parents = dijkstra(graph)
    if parents[n] == -1:
        print(-1)
    else:
        res, parent = [], n - 1
        while parent != parents[0]:
            res.append(parent + 1)
            parent = parents[parent]
        res.reverse()
        print(*res)

BUFSIZE = 8192

main()