#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> pl;
struct edge {
    ll to;     // 辺の行き先
    ll weight; // 辺の重み
    edge(ll t, ll w) : to(t), weight(w) { }
};
typedef vector<vector<ll> > Graph;
typedef vector<vector<edge> > WGraph;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define pb push_back
#define vout(v) for(int i=0; i < v.size(); i++) cout<<v[i]<<' '
#define blank_row cout<<endl
const ll MOD = 1e9 + 7;
const ll INF = MOD*MOD+1;

void dfs(const Graph &G, ll v, vector<bool> &seen, ll &ver, ll &edg){
    seen[v] = true;
    ver++;
    edg += G[v].size();
    for(auto next_v:G[v]){
        if(seen[next_v]) continue;
        dfs(G, next_v, seen, ver, edg);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    Graph G(400000);
    rep(i,n){
        ll a,b;
        cin >> a >> b;
        a--; b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    vector<bool> seen(400000);
    ll ans = 0;
    rep(v, 400000){
        ll ver = 0, edg = 0;
        if(seen[v]) continue;
        dfs(G, v, seen, ver, edg);
        ans += min(ver, edg/2);
    }
    cout << ans << endl;


    return 0;
}

#include <bits/stdc++.h>

using namespace std;
const long long N=200005;

vector<long long> edge[N];

long long tinggi[N];
long long isi[N];
long long berat[N];
long long a[N];
long long b[N];
void cari(long long a,long long harga,long long par){
    berat[a]=isi[a]+harga;
    int banyak=edge[a].size();
    for(int i=0;i<banyak;i++){
        if(edge[a][i]==par)continue;
        cari(edge[a][i],berat[a],a);
    }
    return;
}
void jalanin(long long a,long long b,long long par){
    tinggi[a]=b;
    int banyak=edge[a].size();
    for(int i=0;i<banyak;i++){
        if(edge[a][i]==par)continue;
        jalanin(edge[a][i],b+1,a);
    }
    return;
}
int main(){
    long long i,n,hasil,jum,depan,tambah,harga,levelA,levelB;
    int stat,urutan,tc;
    scanf("%lld", &n);
    getchar();
    for(i=1;i<n;i++){
        scanf("%lld %lld", &a[i], &b[i]);
        getchar();
        edge[a[i]].push_back(b[i]);
        edge[b[i]].push_back(a[i]);
    }
    jalanin(1,0,-1);
    scanf("%d", &tc);
    getchar();
    tambah=0;
    for(i=0;i<tc;i++){
        scanf("%d %d %lld", &stat,&urutan, &harga);
        getchar();
        if(stat==1){
            levelA=tinggi[a[urutan]];
            levelB=tinggi[b[urutan]];
            if(levelA<levelB){
               // cout<<"lili"<<endl;
                isi[b[urutan]]-=harga;
                tambah+=harga;
            }
            else{
                //cout<<"lala"<<endl;
                isi[a[urutan]]+=harga;
            }
        }
        else{
            levelA=tinggi[a[urutan]];
            levelB=tinggi[b[urutan]];
            if(levelA<levelB){
                isi[b[urutan]]+=harga;
                
            }
            else{
                isi[a[urutan]]-=harga;
                tambah+=harga;
            }
        }
    }
    cari(1,0,-1);
    for(i=1;i<=n;i++){
       // cout<<tinggi[i]<<"--"<<endl;
        printf("%lld\n",berat[i]+tambah);
    }
    
    return 0;
}