#ifdef MY
#  include "my_testlib.h"
#else
#  include "testlib.h"
#endif

#include <set>
#include <vector>
#include <algorithm>

using namespace std;

#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define ford(i, n) for(int i = int(n) - 1; i >= 0; --i)
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define X first
#define Y second
#define mp make_pair

#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%lld"
#endif

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

const int N = 50000;

int n;
vector<int> g[N];
int dIn[N];

int p[N];
int w[N];

int findRoot(){
    forn(i, n)
        if(dIn[i] == 0)
            return i;
    return -1;
}

int root;

vector < pair<li, int> > t;

li readAns(InStream& in){
    set<int> can;
    can.insert(root);

    li ans = in.readLong(0, (li)1e18);
    t.clear();

    li tans = 0;

    forn(i, n){
        li si;
        si = in.readLong(0, (li)1e10);

        tans += (si + p[i]) * 1ll * w[i];

        t.pb(mp(si, i));
    }

    if(tans != ans)
        in.quitf(_wa, "printed answer does not correspond with printed sequence ["I64" != "I64"]", tans, ans);

    sort(all(t));
    li ft = 0;
    forn(i, sz(t)){
        li nt = t[i].X;
        int idx = t[i].Y;

        if(!can.count(idx))
            in.quitf(_wa, "incorrect order [try to do %d, root = %d]", idx, root);
        can.erase(idx);
        forn(i, sz(g[idx]))
            can.insert(g[idx][i]);

        if(nt < ft)
            in.quitf(_wa, "two works and the same time ["I64"< "I64"]", nt, ft);
        ft = nt + p[idx];
    }

    return ans;
}

int main(int argc, char** argv){
    registerTestlibCmd(argc, argv);

    n = inf.readInt(1, N); 

    forn(i, n)
        p[i] = inf.readInt(1, 1000);
    forn(i, n)
        w[i] = inf.readInt(1, 1000);

    forn(i, n - 1){
        int v = inf.readInt(1, n);
        int u = inf.readInt(1, n);
        v--; u--;

        g[u].pb(v);
        dIn[v]++;
    }

    root = findRoot();

    li ja = readAns(ans);
    li pa = readAns(ouf);

    if(ja == pa)
        quitf(_ok, "answer is "I64"", ja);
    if(ja < pa)
        quitf(_wa, "jury has "I64" solution, but participant has "I64" solution", ja, pa);
    if(ja > pa)
        quitf(_fail, "jury has "I64" solution, but participant has "I64" solution", ja, pa);        

    return 0;
}