// In the name of god
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define Sort(x) sort(all(x))
#define debug(x) cerr << #x << " :" << x << "\n"
#define use_file freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef string str;

const ll maxn = 4e5 + 5, inf = 1e18, mod = 998244353;
ll n, q, ps[maxn], h[maxn], a[maxn], b[maxn];
vector <ll> adj[maxn];
void dfs(ll u, ll par){
	ps[u] += ps[par];
	for(ll j : adj[u]){
		if(j == par)continue;
		h[j] = h[u] + 1;
		dfs(j, u);
	}
}
int main(){
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for(ll i = 1; i < n; i ++){
		cin >> a[i] >> b[i];
		adj[a[i]].pb(b[i]);
		adj[b[i]].pb(a[i]);
	}
	dfs(1, 0);
	cin >> q;
	while(q --){
		ll t, e, x;
		cin >> t >> e >> x;
		if(t == 1){
			if(h[a[e]] > h[b[e]])ps[a[e]] += x;
			else{
				ps[b[e]] -= x;
				ps[1] += x;
			}
		}
		else{
			if(h[b[e]] > h[a[e]])ps[b[e]] += x;
			else{
				ps[1] += x;
				ps[a[e]] -= x;
			}
		}
	}
	dfs(1, 0);
	for(ll i = 1; i <= n; i ++)cout << ps[i] << "\n";
}

#include <bits/stdc++.h>

using namespace std;
#define ll long long int
#define pb push_back
#define endl "\n"


void dfs(vector<vector<ll>> &adj , vector<bool> &vis ,ll &edges , ll &root , ll start , ll &nov){
	vis[start]=true;
	nov++;
	if(start==root){
		edges += adj[start].size();
	}
	else{
		edges += adj[start].size() - 1;
	}
	for(auto x:adj[start]){
		
		if(vis[x]==false){
			dfs(adj , vis , edges ,root ,  x , nov);
		}
	}
}

int main() {

    //forItachiOfTheLeaf
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin>>n;
    vector<vector<ll>> adj(400004);
    ll i,x,y;
    for(i=0;i<n;i++){
    	cin>>x>>y;
    	adj[x].pb(y);
    	adj[y].pb(x);
    }
    vector<bool> vis(400004 , false);

    ll ans = 0;
    for(i=1;i<=400000;i++){
    	if(vis[i]==false&&adj[i].size()>=1){
    		ll edges = 0 , root = i,nov = 0;
    		dfs(adj , vis , edges , i , i , nov);
    		if(nov==edges+1){
    			ans += nov-1;
    		}
    		else{
    			ans += nov;
    		}

    	}
    }
    cout<<ans<<endl;

}
