#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T1, class T2> inline bool chmax(T1 &a, const T2 &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T1, class T2> inline bool chmin(T1 &a, const T2 &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T> void verr(const set<T> &st) { repa(a, st) cerr << a << " "; cerr << endl; }
template <class S, class T> void verr(const map<S, T> &mp) { repa(a, mp) cerr << "{" << a.first << ", " << a.second << "} "; cerr << endl; }
template <class S, class T, class N> void verr(const vector<pair<S,T>>& a, const N& n) { rep(i, n) cerr << "{" << a[i].first << ", " << a[i].second << "} "; cerr << endl; }
template <class T, class N> void verr(const vector<T>& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << endl; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << endl; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    ll N;
    cin >> N;
    vvc<ll> G(N);
    vc<pair<ll, ll>> E(N - 1);
    rep(i, N - 1){
        ll a, b;
        cin >> a >> b, a--, b--;
        G[a].eb(b), G[b].eb(a);
        E[i] = {a, b};
    }

    vl A(2 * N);
    vl used(N);
    ll r = 0;
    vl in(N), out(N);
    auto dfs = [&](auto&& dfs, ll now) ->void{
        A[r] = now;
        in[now] = out[now] = r++;
        used[now] = true;
        repa(to, G[now]){
            if (used[to]) continue;
            used[to] = true;
            dfs(dfs, to);
            A[r] = now;
            out[now] = r++;
        }
    };
    dfs(dfs, 0);
    // verr(A, A.size());

    vl S(2 * N);
    ll Q;
    cin >> Q;
    rep(_, Q){
        ll t, e, x;
        cin >> t >> e >> x;
        e--;
        auto [a, b] = E[e];
        if(t == 1){
            if(in[a] < in[b]){ // aが根側
                S[0] += x, S[in[b]] -= x;
                S[out[b] + 1] += x, S[2 * N - 1] -= x;
            }else{
                S[in[a]] += x, S[out[a] + 1] -= x;
            }
        }else{
            if(in[b] < in[a]){ // bが根側
                S[0] += x, S[in[a]] -= x;
                S[out[a] + 1] += x, S[2 * N - 1] -= x;
            }else{
                S[in[b]] += x, S[out[b] + 1] -= x;
            }
        }
    }

    // rep(i, N) err(i, in[i], out[i]);

    rep(i, 2 * N - 1) S[i + 1] += S[i];
    // verr(S, 2 * N);
    vl ans(N);
    rep(i, 2 * N - 1) ans[A[i]] = S[i];

    rep(i, N) cout << ans[i] << '\n';
}
//YashS
#include <bits/stdc++.h>
using namespace std;
#define test              int T;cin>>T;while(T--)
#define int               long long
#define pb                push_back
#define all(x)            (x).begin(),(x).end()
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define minf              LONG_LONG_MIN
#define inf              LONG_LONG_MAX
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(x, arr)           memset((arr),x,sizeof((arr))
#define pVec(v)           for(auto e:v)cout<<e<<" ";cout<<"\n"
const int MOD = 1e9 + 7;
const int N = 1e5 + 7;

void init_code() {
#ifndef ONLINE_JUDGE
  freopen("inputf.txt", "r", stdin);
  freopen("outputf.txt", "w", stdout);
#endif // ONLINE_JUDGE
}

void yash()
{
  int n;
  cin >> n;
  vector<int> a(n, 0);
  int sum = 0;
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    sum += a[i];
  }
  vector<bool> f(sum + 1, 0);

  f[0] = 1;
  for (int i = 0; i < n; i++)
  {
    for (int j = sum; j > 0; j--)
    {
      if (j - a[i] >= 0 && f[j - a[i]])
        f[j] = 1;
    }
  }

  int ans = sum;
  for (int i = 1; i < sum; i++)
  {
    if (f[i])
    {
      int ma = (sum - i) > i ? (sum - i) : i;
      if (ma < ans)
        ans = ma;
    }
  }
  cout << ans << endl;
}

signed main()
{
  init_code();
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //test
  yash();
  return 0;
}