stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define rep(i,n) for (int i = 0; i < n; ++i)

using namespace std;

typedef long long ll;



vector<int> to[200005];

vector<int> ans;

void dfs(int x, int p=-1) {

    for (int u : to[x]) {

        if (u == p) continue;

        ans[u] += ans[x];

        dfs(u,x);

    }

}



int main() {

    int n, q;

    cin >> n >> q;

    rep(i,n-1) {

        int a, b;

        cin >> a >> b;

        --a; --b;

        to[a].push_back(b);

        to[b].push_back(a);

    }

    ans.resize(n);

    rep(i,q) {

        int p, x;

        cin >> p >> x;

        --p;

        ans[p] += x;

    }

    dfs(0);

    rep(i,n) {

        if (i != n-1) cout << ans[i] << " ";

        else cout << ans[i] << endl;

    }

    return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define rep(i,n) for (int i = 0; i < n; ++i)

using namespace std;

typedef long long ll;



vector<vector<int>> to;

vector<int> ans;

void dfs(int x, int p=-1) {

    for (int u : to[x]) {

        if (u == p) continue;

        ans[u] += ans[x];

        dfs(u,x);

    }

}



int main() {

    int n, q;

    cin >> n >> q;

    to.resize(n);

    rep(i,n-1) {

        int a, b;

        cin >> a >> b;

        --a; --b;

        to[a].push_back(b);

        to[b].push_back(a);

    }

    ans.resize(n);

    rep(i,q) {

        int p, x;

        cin >> p >> x;

        --p;

        ans[p] += x;

    }

    dfs(0);

    rep(i,n) {

        if (i != n-1) cout << ans[i] << " ";

        else cout << ans[i] << endl;

    }

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
/*

    Problem 26

    https://atcoder.jp/contests/abc138/tasks/abc138_d

*/

#include <iostream>

#include <cstdio>

#include <vector>

#include <algorithm>

#include <map>

#include <numeric>

#include <string>

#include <cmath>

#include <iomanip>

#include <queue>

#include <list>

#include <set>

#include <stack>

#include <cctype>

#include <cmath>

#include <bitset>



using namespace std;

/* typedef */

typedef long long ll;

/* constant */

const int MAX = (2e+5) + 1;

/* global variables */

vector< vector<int> > G(MAX, vector<int>());

vector<int> visited(MAX), counter(MAX);

/* function */

void dfs() {

    stack<int> S;

    S.push(0);

    visited[0] = 1;

    while (!S.empty()) {

        int v = S.top();

        S.pop();

        for (int u : G[v]) {

            if (visited[u]) continue;

            visited[u] = 1;

            counter[u] += counter[v];

            S.push(u);

        }

    }

}

/* main */

int main(){

    int N, Q, a, b, p, x;

    cin >> N >> Q;

    for (int i = 0; i < N - 1; i++) {

        cin >> a >> b;

        a--; b--;

        G[a].push_back(b);

        G[b].push_back(a);

    }

    for (int i = 0; i < Q; i++) {

        cin >> p >> x;

        p--;

        counter[p] += x;

    }

    dfs();

    for (int i = 0; i < N; i++) {

        if (i) cout << ' ';

        cout << counter[i];

    }

    cout << '\n';

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

/* typedef */

typedef long long ll;

typedef pair<int, int> pii;

/* constant */

const int INF = 1 << 30;

const int MAX = 200005;

/* global variables */

vector<vector<int> > G(MAX, vector<int>());

vector<int> counter;

int N;

/* function */

void bfs() {

    vector<int> visited(N, 0);

    stack<int> q;

    q.push(0);

    visited[0] = 1;

    while (!q.empty()) {

        int from = q.top(); q.pop();

        for (int to : G[from]) {

            if (visited[to]) continue;

            counter[to] += counter[from];

            visited[to] = 1;

            q.push(to);

        }

    }

}



/* main */

int main(){

    int Q, a, b, p, x;

    cin >> N >> Q;

    for (int i = 0; i < N - 1; i++) {

        cin >> a >> b;

        a--; b--;

        G[a].push_back(b);

        G[b].push_back(a);

    }

    counter.assign(N, 0);

    for (int i = 0; i < Q; i++) {

        cin >> p >> x;

        p--;

        counter[p] += x;

    }

    bfs();

    for (int c : counter) cout << c << ' ';

    cout << '\n';

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



#define rep(i, n) for (int i = 0; i < (n); i++)

#define repr(i, n) for (int i = (n)-1; i >= 0; i--)

using namespace std;

typedef long long ll;



const int N = 2 * 1e5 + 5;

int n, q, a, b;

vector<int> r[N], ans(N);



void dfs(int v, int p = -1) {

  for (int u : r[v]) {

    if (u == p) continue;

    ans[u] += ans[v];

    dfs(u, v);

  }

  return;

}



int main() {

  cin >> n >> q;

  int p, x;

  rep(i, n - 1) cin >> a >> b, a--, b--, r[a].push_back(b), r[b].push_back(a);

  rep(i, q) {

    cin >> p >> x, p--;

    ans[p] += x;

  }

  dfs(0);



  rep(i, n) cout << ans[i] << " ";

  cout << endl;

  return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



#define rep(i, n) for (int i = 0; i < (n); i++)

#define repr(i, n) for (int i = (n)-1; i >= 0; i--)

using namespace std;

typedef long long ll;



const int N = 2 * 1e5 + 5;

int n, q, a, b;

vector<vector<int>> r;

vector<int> ans;



void dfs(int v, int p = -1) {

  for (int u : r[v]) {

    if (u == p) continue;

    ans[u] += ans[v];

    dfs(u, v);

  }

}



int main() {

  cin >> n >> q;

  int p, x;

  r.resize(n);

  ans.resize(n);

  rep(i, n - 1) cin >> a >> b, a--, b--, r[a].push_back(b), r[b].push_back(a);

  rep(i, q) cin >> p >> x, p--, ans[p] += x;

  dfs(0);

  rep(i, n) cout << ans[i] << " ";

  cout << endl;

  return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define ll long long

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

using namespace std;



ll N, Q;

//値

vector<ll> value((ll)2e5,0);

//使用したかどうか

vector<bool> used((ll)2e5,false);

//連結リスト

vector<vector<ll>> G((ll)2e5);



void solve(ll n)

{

    rep(i,G.at(n).size()){

        ll nextNode =G.at(n).at(i); 

        if(used.at(nextNode))continue;

        used.at(n) = true;

        value.at(nextNode) += value.at(n);

        solve(nextNode);

        used.at(n) = false;

    }

    return;

}



int main(void)

{

    cin >> N >> Q;



    rep(i, N - 1)

    {

        ll a, b;

        cin >> a >> b;

        a--;

        b--;

        G.at(a).push_back(b);

        G.at(b).push_back(a);

    }



    rep(i, Q)

    {

        ll p, x;

        cin >> p >> x;

        p--;

        value.at(p) += x;

    }

    solve(0);

    rep(i,N){

        if(i>0)cout << " ";

        cout << value.at(i);

    }

    cout << endl;

}




// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define ll long long

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

using namespace std;



class Node

{

public:

    ll val;

};



class Graph

{

public:

    vector<Node> Nodes;

    vector<vector<ll>> G;

    Graph(ll N)

    {

        this->G = vector<vector<ll>>(N);

        this->Nodes = vector<Node>(N);

    };

    void addEdge(ll a, ll b)

    {

        this->G[a].push_back(b);

        this->G[b].push_back(a);

    };

};





int main(void)

{

    ll N, Q;

    cin >> N >> Q;

    Graph g(N);

    

    rep(i, N - 1)

    {

        ll a, b;

        cin >> a >> b;

        a--;

        b--;

        g.addEdge(a,b);

    }



    rep(i, Q)

    {

        ll p, x;

        cin >> p >> x;

        p--;

        g.Nodes[p].val += x;

    }



    //根から全ての木をたどる

    auto dps = [&](auto dps, ll n, ll p) -> void {

        for_each(g.G[n].begin(), g.G[n].end(), [&](auto v) {

            if (v != p)

            {

                g.Nodes[v].val += g.Nodes[n].val;

                dps(dps, v, n);

            }

        });

        return;

    };



    dps(dps, 0, -1);

    rep(i, N)

    {

        if (i > 0)

            cout << " ";

        cout << g.Nodes[i].val;

    }

    cout << endl;

}






// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <string>

#include <vector>

#include <iomanip>

#include <algorithm>



using namespace std;



vector<vector<int>> Graph(200001); // 要素数0の2次元配列 無向グラフ

vector<long long> counter(200001, 0);

vector<bool> seen(200001, false);



void dfs(int now){

    seen[now] = true;



    for (int next : Graph[now]){

        if (seen[next] == false){

            counter[next] += counter[now];

            dfs(next);

        }

    }

}



int main(){

    int N, Q;

    cin >> N >> Q;

    vector<int> a(N-1), b(N-1), p(Q), x(Q);

    for (int i = 0; i < N-1; i++){

        cin >> a[i] >> b[i];

        a[i]--;

        b[i]--;

        Graph[a[i]].emplace_back(b[i]);

        Graph[b[i]].emplace_back(a[i]);

    }

    for (int i = 0; i < Q; i++){

        cin >> p[i] >> x[i];

        p[i]--;

        counter[p[i]] += x[i];  // 各クエリの頂点のみに加算

    }



    dfs(0);



    for (int i = 0; i < N-1; i++){

        cout << counter[i] << " ";

    }

    cout << counter[N-1] << endl;



    return 0;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <string>

#include <vector>

#include <iomanip>

#include <algorithm>

#include <queue>



using namespace std;



int main(){

    int N, Q;

    cin >> N >> Q;

    vector<int> a(N-1), b(N-1), p(Q), x(Q);

    vector<vector<int>> Graph(N);

    vector<long long> counter(N, 0);



    for (int i = 0; i < N-1; i++){

        cin >> a[i] >> b[i];

        a[i]--;

        b[i]--;

        Graph[a[i]].emplace_back(b[i]);

        Graph[b[i]].emplace_back(a[i]);

    }

    for (int i = 0; i < Q; i++){

        cin >> p[i] >> x[i];

        p[i]--;

        counter[p[i]] += x[i];  // 各クエリの頂点のみに加算

    }



    // BFS

    vector<int> dist(N, -1);

    queue<int> q;

    q.push(0);

    dist[0] = 0;

    while(!q.empty()){

        int now = q.front();

        q.pop();

        for (int next : Graph[now]){

            if (dist[next] == -1) {

                dist[next] = dist[now] + 1;

                counter[next] += counter[now];

                q.push(next);

            }

        }

    }



    for (int i = 0; i < N-1; i++){

        cout << counter[i] << " ";

    }

    cout << counter[N-1] << endl;



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <functional>

#include <algorithm>

#include <string>

#include <vector>

#include <set>

#include <map>

#include <queue>

#include <stack>

using namespace std;

template<class T, class Compare = less<T> >

using MaxHeap = priority_queue<T, vector<T>, Compare>;

template<class T, class Compare = greater<T> >

using MinHeap = priority_queue<T, vector<T>, Compare>;

using llong = long long;



llong n, q;

vector<llong> G[200005];

llong x[200005];

bool visit[200005];



void dfs(llong pos) {

    visit[pos] = 1;

    for (int i = 0; i < G[pos].size(); i++) {

        if (!visit[G[pos][i]]) {

            visit[G[pos][i]] = 1;

            x[G[pos][i]] += x[pos];

            dfs(G[pos][i]);

        }

    }

    return;

}



int main() {

    cin >> n >> q;

    for (int i = 0; i < n - 1; i++) {

        llong a, b;

        cin >> a >> b;

        G[a].push_back(b);

        G[b].push_back(a);

    }

    for (int i = 0; i < q; i++) {

        llong a, b;

        cin >> a >> b;

        x[a] += b;

    }



    dfs(1);



    for (int i = 1; i <= n; i++) {

        if (i > 1) cout << ' ';

        cout << x[i];

    }

    cout << endl;



    return 0;

}


// Optimized solution to the same problem (faster):
#define _overload(_1, _2, _3, _4, name, ...) name

#define _rep1(Itr, N) _rep3(Itr, 0, N, 1)

#define _rep2(Itr, a, b) _rep3(Itr, a, b, 1)

#define _rep3(Itr, a, b, step) for (llong (Itr) = a; (Itr) < b; (Itr) += step)

#define repeat(...) _overload(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__)



#include <iostream>

#include <vector>

using namespace std;

using llong = long long;



llong n, q;

vector<vector<int>> g;

vector<llong> cnt;

vector<llong> ans;



void dfs(int u, int par, llong c) {

    c += cnt[u];

    ans[u] = c;



    for (auto vs:g[u]) {

        if (vs == par) continue;

        dfs(vs, u, c);

    }

}



int main() {

    cin >> n >> q;



    g.resize(n + 1);

    cnt.resize(n + 1);

    ans.resize(n + 1);

    repeat(i, n - 1) {

        llong a, b;

        cin >> a >> b;

        g[a].push_back(b);

        g[b].push_back(a);

    }



    repeat(i, q) {

        llong p, x;

        cin >> p >> x;

        cnt[p] += x;

    }



    dfs(1, 0, 0);



    repeat(i, 1, n + 1) {

        cout << ans[i] << ' ';

    }



    return 0;

};


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N=2e5+100;

vector<int>ve[N];

int ans[N];

int vis[N];

queue<int>q;

void bfs()

{



    q.push(1);

    vis[1]=1;

    while(q.size()){

        int k=q.front();q.pop();

        for(auto v:ve[k]){

            if(!vis[v]){

                ans[v]+=ans[k];

                vis[v]=1;

                q.push(v);

            }

        }

    }

}

int main()

{

     ios::sync_with_stdio(0);cin.tie(0);

     int n,q;

     cin>>n>>q;

     for(int i=1;i<=n-1;i++){

         int a,b;

         cin>>a>>b;

         ve[a].push_back(b);

         ve[b].push_back(a);

     }

     for(int i=1;i<=q;i++){

        int a,b;

        cin>>a>>b;

        ans[a]+=b;

     }

     bfs();

     for(int i=1;i<=n;i++){

        cout<<ans[i]<<" ";

     }

     return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;

typedef long long ll;





const int N=2e5+100;



ll cnt[N];

struct edge

{

    int to,next;

}ed[N*2];



int head[N];

int tot=1;

int vis[N];

void add_edge(int u,int v)

{

    ed[tot].to=v;

    ed[tot].next=head[u];

    head[u]=tot++;

}



void bfs()

{

    queue<int>q;q.push(1);

    vis[1]=1;

    while(q.size()){

        int k=q.front();q.pop();

        for(int i=head[k];i;i=ed[i].next){

            int kk=ed[i].to;

            if(!vis[kk]){

            cnt[kk]+=cnt[k];

            q.push(kk);

            vis[k]=1;

            }

        }

    }

}



int main()

{

    int n,m;

    int u,v;

    scanf("%d%d",&n,&m);

    for(int i=1;i<n;i++){

        scanf("%d%d",&u,&v);

        add_edge(u,v);

        add_edge(v,u);

    }

    for(int i=1;i<=m;i++){

        scanf("%d%d",&u,&v);

        cnt[u]+=v;

    }

    bfs();

    for(int i=1;i<=n;i++){

        printf("%lld ",cnt[i]);

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll MOD = pow(10, 9) + 7;

//const ll MOD = 998244353;

//const ll MOD = ;

ll mod(ll A, ll M) {return (A % M + M) % M;}

const ll INF = 1LL << 60;

template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}

template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}

ll divCeil(ll A, ll B) {return (A + (B - 1)) / B;}

ll myctoi(char C) {return C - '0';}

char myitoc(ll N) {return '0' + N;}

#define FINALANS(A) {cout << (A) << endl; exit(0);}



vector<vector<ll>> G(222222);

vector<ll> cnt(222222, 0);

vector<bool> visited(222222, false);

void dfs(ll V)

{

  if (visited.at(V))

    return;

  visited.at(V) = true;



  //cerr << V << endl;



  for (ll i = 0; i < G.at(V).size(); i++)

  {

    if (!visited.at(G.at(V).at(i)))

      cnt.at(G.at(V).at(i)) += cnt.at(V);

    dfs(G.at(V).at(i));

  }

}



int main()

{

  ll N, Q;

  cin >> N >> Q;

  for (ll i = 0; i < N - 1; i++)

  {

    ll a, b;

    cin >> a >> b;

    a--, b--;

    G.at(a).push_back(b);

    G.at(b).push_back(a);

  }

  for (ll i = 0; i < Q; i++)

  {

    ll p, x;

    cin >> p >> x;

    p--;

    cnt.at(p) += x;

  }



  dfs(0);



  for (ll i = 0; i < N; i++)

  {

    cout << cnt.at(i);

    if (i == N - 1)

      cout << endl;

    else

      cout << " ";

  }

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

constexpr ll MOD = 1e9 + 7;

//constexpr ll MOD = 998244353;

//constexpr ll MOD = ;

ll mod(ll A, ll M) {return (A % M + M) % M;}

constexpr ll INF = 1LL << 60;

template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}

template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}

ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}

#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)



int main()

{

  ll N, Q;

  cin >> N >> Q;

  vector<vector<ll>> G(N);

  for (ll i = 0; i < N - 1; i++)

  {

    ll a, b;

    cin >> a >> b;

    a--, b--;

    G.at(a).push_back(b);

    G.at(b).push_back(a);

  }



  vector<ll> cnt(N);

  for (ll i = 0; i < Q; i++)

  {

    ll p, x;

    cin >> p >> x;

    p--;

    cnt.at(p) += x;

  }



  vector<bool> visited(N, false);

  vector<ll> st;

  visited.at(0) = true;

  st.push_back(0);

  while (!st.empty())

  {

    ll v = st.back();

    st.pop_back();



    for (auto nv : G.at(v))

    {

      if (visited.at(nv))

        continue;



      cnt.at(nv) += cnt.at(v);

      visited.at(nv) = true;

      st.push_back(nv);

    }

  }



  for (ll i = 0; i < N; i++)

  {

    cout << cnt.at(i) << ((i == N - 1) ? '\n' : ' ');

  }

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

const LL N = 200010;

struct Edge

{

    LL next;

    LL dis;

    LL to;

}edge[N*2];

LL head[N*2];

LL res[N*2];

LL r[N*2];

LL tot;

LL n,m;

bool vis[N*2];

inline void add(LL from,LL to)

{

    edge[++tot].next = head[from];

    edge[tot].to = to;

    head[from] = tot;

}

void init()

{

    memset(head,-1,sizeof(head));

}

void bfs()

{

   queue<LL> Q;

   Q.push(1);

   while(Q.size())

   {

       LL x = Q.front();

       vis[x] = 1;

       Q.pop();

       for(LL i = head[x];~i;i = edge[i].next)

       {

           LL y = edge[i].to;

         if(!vis[y]) {

           res[y] += res[x];

           Q.push(y);

       }

       }

   }



}

int main()

{

  //freopen("input.txt","r",stdin);

   init();

   scanf("%lld%lld",&n,&m);

   LL f,t;

   for(LL i = 1;i<=n-1;++i)

   {

       scanf("%lld%lld",&f,&t);

       add(f,t);

       add(t,f);

   }

   for(LL i = 1;i<=m;++i)

   {

       scanf("%lld%lld",&f,&t);

       res[f] += t;

   }

   bfs();

   for(LL i = 1;i<=n;++i)

    printf("%lld ",res[i]);

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N = 200010;

struct Edge

{

    int next;

    int dis;

    int to;

}edge[N*2];

int head[N*2];

int res[N*2];

int r[N*2];

int tot;

int n,m;

bool vis[N*2];

inline void add(int from,int to)

{

    edge[++tot].next = head[from];

    edge[tot].to = to;

    head[from] = tot;

}

void init()

{

    memset(head,-1,sizeof(head));

}

void dfs(int id)

{

    vis[id] = 1;

    for(int i = head[id];~i;i = edge[i].next)

    {

        int y = edge[i].to;

        if(!vis[y]) res[y] += res[id],dfs(y);

    }

}

int main()

{

  //freopen("input.txt","r",stdin);

   init();

   scanf("%d%d",&n,&m);

   int f,t;

   for(int i = 1;i<=n-1;++i)

   {

       scanf("%d%d",&f,&t);

       add(f,t);

       add(t,f);

   }

   for(int i = 1;i<=m;++i)

   {

       scanf("%d%d",&f,&t);

       res[f] += t;

   }

   dfs(1);

   for(int i = 1;i<=n;++i)

    printf("%d ",res[i]);

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

#include <algorithm>

#include <numeric>

#include <cmath>

#include <limits>

#include <numeric>

#include <map>

#include <cstring>

using namespace std;



void AddScore(map<long long, vector<long long>>& C, long long* S, long long i, bool* visited)

{

    if (C[i].size() == 0) {

        return;

    }

    auto r = C[i];

    auto s = S[i - 1];

    visited[i] = true;

    for (auto j : r) {

        if (visited[j]) {

            continue;

        }

        S[j - 1] += s;

        AddScore(C, S, j, visited);

    }

}



int main()

{

    long long N, Q;

    cin >> N;

    cin >> Q;



    map<long long, vector<long long>> C;

    for (long long i = 0; i < N - 1; i++) {

        long long a, b;

        cin >> a;

        cin >> b;

        C[a].push_back(b);

        C[b].push_back(a);

    }



    long long S[200001];

    memset(S, 0, sizeof(S));

    for (long long i = 0; i < Q; i++) {

        long long p, x;

        cin >> p;

        cin >> x;

        S[p - 1] += x;

    }



    bool visited[200001];

    memset(visited, 0, sizeof(visited));



    AddScore(C, S, 1, visited);



    for (long long i = 0; i < N; ++i) {

        cout << S[i] << " ";

    }

    cout << endl;



    return 0;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <vector>

#include <algorithm>

#include <numeric>

#include <cmath>

#include <limits>

#include <numeric>

#include <map>

#include <cstring>

using namespace std;



void AddScore(map<long long, vector<long long>>& C, long long* S, long long i, int* visited)

{

    const auto r = C[i];

    if (r.size() == 0) {

        return;

    }

    const auto s = S[i - 1];

    visited[i - 1] = true;

    for (auto j : r) {

        if (visited[j - 1] != 0) {

            continue;

        }

        S[j - 1] += s;

        AddScore(C, S, j, visited);

    }

}



int main()

{

    long long N, Q;

    cin >> N;

    cin >> Q;



    map<long long, vector<long long>> C;

    for (long long i = 0; i < N - 1; i++) {

        long long a, b;

        cin >> a >> b;

        C[a].push_back(b);

        C[b].push_back(a);

    }



    vector<long long> S;

    S.resize(N);

    memset(S.data(), 0, sizeof(S[0]) * N);

    for (long long i = 0; i < Q; i++) {

        long long p, x;

        cin >> p >> x;

        S[p - 1] += x;

    }



    vector<int> visited;

    visited.resize(N);

    memset(visited.data(), 0, sizeof(visited[0])*N);



    AddScore(C, S.data(), 1, visited.data());



    for (long long i = 0; i < N; ++i) {

        cout << S[i] << " ";

    }

    cout << endl;



    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;

const int MAX=2e5+10;

vector<int>g[MAX];

ll sub[MAX],ans[MAX];

void dfs(int u,int par)

{

    ans[u]+=sub[u];

    for(int v:g[u])

    {

        if(v==par)continue;

        ans[v]+=ans[u];

        dfs(v,u);

    }

}

int main ()

{

    int N,u,v,Q;cin >> N >> Q;

    for(int i=1;i<=N-1;i++){

        cin >> u >> v;

        g[u].push_back(v);

        g[v].push_back(u);

    }

    while(Q--)

    {

        int u,p;cin >> u >> p;

        sub[u]+=p;

    }

    dfs(1,0);

    for(int i=1;i<=N;i++)cout<<ans[i]<<" ";

    return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <queue>

#include <cstring>

#include <algorithm>

using namespace std;

const int maxd = 2e5+10;

struct node

{

	int v,net;

}e[maxd<<1];

int f[maxd],eid;

void insert(int x,int y)

{

	e[eid].v = y;

	e[eid].net =f[x];

	f[x] = eid++;

}

void init()

{

	memset(f,-1,sizeof(f));

	eid = 0;

}

long long t[maxd];

void dfs(int x,int fa = 0)

{

	for(int i=f[x];i+1;i=e[i].net)

	{

		int v = e[i].v;

		if(v == fa) continue;

		t[v] += 1ll * t[x];

		dfs(v,x);

	}

}

int main()

{

	// freopen("a.in","r",stdin);

	// freopen("k.out","w",stdout);

	int n,m;scanf("%d %d",&n,&m);

	init();

	for(int i=1;i<n;i++)

	{

		int a,b;

		scanf("%d %d",&a,&b);

		insert(a,b);insert(b,a);

	}

	for(int i=1;i<=m;i++)

	{

		int a,b;

		scanf("%d %d",&a,&b);

		t[a]+=b;

	}

	dfs(1);

	for(int i=1;i<=n;i++) printf("%lld ",t[i]);

	return 0;

}

// Fastest known solution for this problem: