#include <bits/stdc++.h>
using namespace std;
const unsigned long long MOD = 1e9 + 7;
const int INF = (int)2e9 + 7;
const long long LINF = (long long)1e18;
const unsigned long long mod1 = 183453789;
const unsigned long long mod2 = 1234567891;
const int P1 = 337, P2 = 263;
template<typename T>
T input(){
T ans = 0, m = 1; char c = ' ';
while (!((c >= '0' && c <= '9') || c == '-')) c = getchar();
if (c == '-') m = -1, c = getchar();
while (c >= '0' && c <= '9') ans = ans * 10 + (c - '0'), c = getchar();
return ans * m;
}
string nextString(bool flag = false){
char ch; string ans = "";
do { ch = getchar(); } while(ch <= ' ');
while(1) {
ans += ch; ch = getchar();
if ( (!flag && ch <= ' ') || (flag && ch < ' ') ) break;
}
return ans;
}
char nextChar(){
char ch;
do {ch = getchar(); } while(ch <= ' ');
return ch;
}
void read(string& s){ s = nextString(); }
void read(char& c){ c = nextChar(); }
template<typename T> void read(T& a){ a = input<T>(); }
template<typename T, typename... R> void read(T& a, R&... r){ read(a); read(r...); }
const int N = 1e5 + 10;
struct Segment {
int l, r;
Segment() : l(-INF), r(INF) {}
Segment(int l, int r) : l(l), r(r) {}
Segment operator+(const Segment& other) const {
return Segment(l + other.l, r + other.r);
}
bool operator==(const Segment& other) const {
return l == other.l && r == other.r;
}
bool isOk() {
return l <= r;
}
};
Segment combine(const Segment& a, const Segment& b){
return Segment(max(a.l, b.l), min(a.r, b.r));
}
vector < Segment > pref[N];
vector < Segment > suff[N];
vector < int > g[N];
Segment seg[N], f[N], fd[N];
int ans[N];
void preDfs(int v, int p){
for (auto to: g[v]){
if (to == p) continue;
preDfs(to, v);
pref[v].push_back(f[to]);
suff[v].push_back(f[to]);
fd[v] = combine(fd[v], f[to]);
}
int k = (int)pref[v].size();
for (int i = 1; i < k; ++ i){
pref[v][i] = combine(pref[v][i], pref[v][i - 1]);
suff[v][k - i - 1] = combine(suff[v][k - i - 1], suff[v][k - i]);
}
f[v] = fd[v] + seg[v];
if (fd[v] == Segment())
f[v] = seg[v];
if (!fd[v].isOk())
f[v] = {INF, -INF};
}
void dfs(int v, int p, const Segment& cur){
//cerr << v + 1 << " (" << cur.l << ", " << cur.r << ") (" << fd[v].l << ", " << fd[v].r << ")" << endl;
ans[v] = combine(cur, fd[v]).isOk();
for (int i = 0, ptr = 0; i < g[v].size(); ++ i){
int to = g[v][i];
if (to == p) continue;
Segment newSeg = cur;
if (ptr)
newSeg = combine(newSeg, pref[v][ptr - 1]);
if (ptr < (int)pref[v].size() - 1)
newSeg = combine(newSeg, suff[v][ptr + 1]);
if (newSeg == Segment())
newSeg = seg[v];
else
if (!newSeg.isOk())
newSeg = {INF, -INF};
else
newSeg = newSeg + seg[v];
dfs(to, v, newSeg);
ptr ++;
}
}
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#else
freopen("lamps.in", "r", stdin);
freopen("lamps.out", "w", stdout);
#endif
int n; read(n);
for (int i = 0; i < n - 1; ++ i){
int u, v;
read(u, v);
u --, v --;
g[u].push_back(v);
g[v].push_back(u);
}
for (int i = 0; i < n; ++ i){
read(seg[i].l, seg[i].r);
}
preDfs(0, -1);
dfs(0, -1, Segment());
for (int i = 0; i < n; ++ i){
cout << ans[i] << " ";
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiAgIAp1c2luZyBuYW1lc3BhY2Ugc3RkOwpjb25zdCB1bnNpZ25lZCBsb25nIGxvbmcgTU9EID0gMWU5ICsgNzsKY29uc3QgaW50IElORiA9IChpbnQpMmU5ICsgNzsKY29uc3QgbG9uZyBsb25nIExJTkYgPSAobG9uZyBsb25nKTFlMTg7CmNvbnN0IHVuc2lnbmVkIGxvbmcgbG9uZyBtb2QxID0gMTgzNDUzNzg5Owpjb25zdCB1bnNpZ25lZCBsb25nIGxvbmcgbW9kMiA9IDEyMzQ1Njc4OTE7CmNvbnN0IGludCBQMSA9IDMzNywgUDIgPSAyNjM7CiAKdGVtcGxhdGU8dHlwZW5hbWU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pbnQgTiA9IDFlNSArIDEwOwogCnN0cnVjdCBTZWdtZW50IHsKICAgIGludCBsLCByOwogICAgU2VnbWVudCgpIDogbCgtSU5GKSwgcihJTkYpIHt9CiAgICBTZWdtZW50KGludCBsLCBpbnQgcikgOiBsKGwpLCByKHIpIHt9CiAgICBTZWdtZW50IG9wZXJhdG9yKyhjb25zdCBTZWdtZW50JiBvdGhlcikgY29uc3QgewogICAgICAgIHJldHVybiBTZWdtZW50KGwgKyBvdGhlci5sLCByICsgb3RoZXIucik7CiAgICB9CiAgICBib29sIG9wZXJhdG9yPT0oY29uc3QgU2VnbWVudCYgb3RoZXIpIGNvbnN0IHsKICAgICAgICByZXR1cm4gbCA9PSBvdGhlci5sICYmIHIgPT0gb3RoZXIucjsKICAgIH0KICAgIGJvb2wgaXNPaygpIHsKICAgICAgICByZXR1cm4gbCA8PSByOwogICAgfQp9OwogClNlZ21lbnQgY29tYmluZShjb25zdCBTZWdtZW50JiBhLCBjb25zdCBTZWdtZW50JiBiKXsKICAgIHJldHVybiBTZWdtZW50KG1heChhLmwsIGIubCksIG1pbihhLnIsIGIucikpOwp9CiAKdmVjdG9yIDwgU2VnbWVudCA+IHByZWZbTl07CnZlY3RvciA8IFNlZ21lbnQgPiBzdWZmW05dOwogCnZlY3RvciA8IGludCA+IGdbTl07ClNlZ21lbnQgc2VnW05dLCBmW05dLCBmZFtOXTsKaW50IGFuc1tOXTsKIAp2b2lkIHByZURmcyhpbnQgdiwgaW50IHApewogICAgZm9yIChhdXRvIHRvOiBnW3ZdKXsKICAgICAgICBpZiAodG8gPT0gcCkgY29udGludWU7CiAgICAgICAgcHJlRGZzKHRvLCB2KTsKICAgICAgICBwcmVmW3ZdLnB1c2hfYmFjayhmW3RvXSk7CiAgICAgICAgc3VmZlt2XS5wdXNoX2JhY2soZlt0b10pOwogICAgICAgIGZkW3ZdID0gY29tYmluZShmZFt2XSwgZlt0b10pOwogICAgfQogICAgaW50IGsgPSAoaW50KXByZWZbdl0uc2l6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ZWcgPT0gU2VnbWVudCgpKQogICAgICAgICAgICBuZXdTZWcgPSBzZWdbdl07CiAgICAgICAgZWxzZQogICAgICAgIGlmICghbmV3U2VnLmlzT2soKSkKICAgICAgICAgICAgbmV3U2VnID0ge0lORiwgLUlORn07CiAgICAgICAgZWxzZQogICAgICAgICAgICBuZXdTZWcgPSBuZXdTZWcgKyBzZWdbdl07CiAKICAgICAgICBkZnModG8sIHYsIG5ld1NlZyk7CiAgICAgICAgcHRyICsrOwogICAgfQp9CiAKaW50MzJfdCBtYWluKCl7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOyBjaW4udGllKDApOwogICAgI2lmZGVmIExPQ0FMCiAgICAgICAgZnJlb3BlbigiaW4udHh0IiwgInIiLCBzdGRpbik7CiAgICAgICAgZnJlb3Blbigib3V0LnR4dCIsICJ3Iiwgc3Rkb3V0KTsKICAgICNlbHNlCiAgICAgICAgZnJlb3BlbigibGFtcHMuaW4iLCAiciIsIHN0ZGluKTsKICAgICAgICBmcmVvcGVuKCJsYW1wcy5vdXQiLCAidyIsIHN0ZG91dCk7CiAgICAjZW5kaWYKICAgIGludCBuOyByZWFkKG4pOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuIC0gMTsgKysgaSl7CiAgICAgICAgaW50IHUsIHY7CiAgICAgICAgcmVhZCh1LCB2KTsKICAgICAgICB1IC0tLCB2IC0tOwogICAgICAgIGdbdV0ucHVzaF9iYWNrKHYpOwogICAgICAgIGdbdl0ucHVzaF9iYWNrKHUpOwogICAgfQogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyArKyBpKXsKICAgICAgICByZWFkKHNlZ1tpXS5sLCBzZWdbaV0ucik7CiAgICB9CiAgICBwcmVEZnMoMCwgLTEpOwogICAgZGZzKDAsIC0xLCBTZWdtZW50KCkpOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBuOyArKyBpKXsKICAgICAgICBjb3V0IDw8IGFuc1tpXSA8PCAiICI7CiAgICB9Cn0=