#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

template <typename T>
T mypow(T x, T n, const T &p = -1)
{ //x^nをmodで割った余り
	T ret = 1;
	while (n > 0)
	{
		if (n & 1)
		{
			if (p != -1)
				ret = (ret * x) % p;
			else
				ret *= x;
		}
		if (p != -1)
			x = (x * x) % p;
		else
			x *= x;
		n >>= 1;
	}
	return ret;
}

using namespace std;
// using namespace atcoder;

void solve()
{
	int n;
	cin>>n;
	vector<pair<int,int>>e(n-1);
	vector<vector<int>>g(n);
	rep(i,n-1){
		cin>>e[i].first>>e[i].second;
		e[i].first--;e[i].second--;
		g[e[i].first].eb(e[i].second);
		g[e[i].second].eb(e[i].first);
	}
	vector<int>dis(n);
	auto dfs=[&](auto self,int v,int par=-1)->void{
		for(auto x:g[v]){
			if(x!=par){
				dis[x]=dis[v]+1;
				self(self,x,v);
			}
		}
	};
	dfs(dfs,0);
	vector<ll>add(n);
	int q;
	cin>>q;
	while(q--){
		int u,v;
		ll t;
		cin>>u>>v>>t;
		u--;
		v--;
		int a=e[v].first,b=e[v].second;
		if(dis[b]<dis[a]){
			u^=1;
		}
		if(u==0){
			add[0]+=t;
			if(dis[a]<=dis[b]){
				add[b]-=t;
			}
			else add[a]-=t;
		}
		else{
			if(dis[a]<=dis[b])add[b]+=t;
			else add[a]+=t;
		}
	}
	auto rec=[&](auto self,int v,int par=-1)->void{
		for(auto x:g[v]){
			if(par!=x){
				add[x]+=add[v];
				self(self,x,v);
			}
		}
	};
	rec(rec,0);
	rep(i,n){
		cout<<add[i]<<"\n";
	}
}

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

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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
// #define int long long

typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n;
int c[N];
vector<int> g[N];
vector<int> good_vers;
int cnt_colors[N];

void dfs(int v, int p) {
	if (cnt_colors[c[v]] == 0) good_vers.push_back(v);
	cnt_colors[c[v]] += 1;
	for(int u:g[v]) {
		if (u == p) continue;
		dfs(u, v);
	}
	cnt_colors[c[v]] -= 1;
}
int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n;
	for(int i=0; i<n; i++) cin >> c[i];
	for(int i=0; i<n-1; i++) {
		int u, v; cin >> u >> v;
		u--, v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(0, -1);
	sort(good_vers.begin(), good_vers.end());
	for(int v:good_vers) cout << v + 1 << endl;
	return 0;
}
