stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#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;

}




// Faster C++ solution for the same problem (measured speedup: 8.21835637265277x):
#include <bits/stdc++.h>

#define ll long long

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

using namespace std;



int main(void)

{

    ll N, Q;

    cin >> N >> Q;

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

    vector<ll> value(N);

    rep(i, N - 1)

    {

        ll a, b;

        cin >> a >> b;

        a--;b--;

        G[a].push_back(b);

        G[b].push_back(a);

    }



    rep(i, Q)

    {

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

        value[p] += x;

    }



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

        for (auto v : G[n])

            if (v != p)

            {

               value[v] += value[n];

                solve(solve, v, n);

            }

        return;

    };



    solve(solve, 0, -1);

    rep(i, N)

    {

        if (i > 0)

            cout << " ";

        cout << value[i];

    }

    cout << endl;

}
// Slower C++ solution:
#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;

}




// Faster C++ solution for the same problem (measured speedup: 8.28569893306643x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 8.367025119552904x):
#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;

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 6.453468521239511x):
#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;

};
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 6.527227007480714x):
#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;

}
// Slower C++ solution:
#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 << " ";

  }

}

// Faster C++ solution for the same problem (measured speedup: 9.230318643637906x):
#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' : ' ');

  }

}
// Slower C++ solution:
#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]);

}


// Faster C++ solution for the same problem (measured speedup: 1.628845755578837x):
#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]);

}
// Slower C++ solution:
#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;

}


// Faster C++ solution for the same problem (measured speedup: 2.7978076345423286x):
#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;

}
// Slower C++ solution:
#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;

}

// Faster C++ solution for the same problem (measured speedup: 6.5240321437860525x):
#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;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

#define fi first

#define se second

#define pb push_back

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

#define for1(i,n) for(int i=1;i<=n;i++)

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

#define all(x) x.begin(), x.end()

const int MAXN = 2e5 +5;



void fio(){

  ios::sync_with_stdio(0);

  cin.tie(0);

  cout.tie(0);

}



vector <vector <int> > adj(MAXN);

int n;

vector <int> in(MAXN), out(MAXN), vec;



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

  vec.pb(i);

  in[i] = vec.size()-1;

  for(auto j:adj[i])

    if(j!=p) dfs(j,i);

  out[i] = vec.size()-1;

}







int main(){

  fio();

  int q; cin>>n>>q;

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

    int u,v; cin>>u>>v;

    adj[u].pb(v);

    adj[v].pb(u);

    } 

  dfs(1);

  vector <LL> an(n+5);

  while(q--){

    LL u,x; cin>>u>>x;

    an[in[u]]+=x;

    an[out[u]+1]-=x;

  }

  for1(i,n)

    an[i]+=an[i-1];

  for1(i,n) 

    cout<<an[in[i]]<<" ";

  cout<<endl;

  return 0;

}




// Faster C++ solution for the same problem (measured speedup: 1.3087569233830165x):
#include <bits/stdc++.h>

using namespace std;



const int MAXN = 2 * 100 * 1000 + 10;

int n, q, a, b, sumx, val[MAXN], jav[MAXN], x;

vector <int> adj[MAXN];

bool mark[MAXN];



void dfs(int v) {

    x += val[v];

    mark[v] = 1;

    jav[v] = x;

    for (int i : adj[v])

        if (!mark[i])

            dfs(i);

    x -= val[v];

}

void input(){

    cin >> n >> q;

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

        cin >> a >> b;

        adj[a].push_back(b);

        adj[b].push_back(a);

    }

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

        cin >> a >> b;

        val[a] += b;

    }

}

void output() {

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

        cout << jav[i] << " ";

    cout << endl;

}

void solve() {

    input();

    dfs(1);

    output();

}



int main() {

    solve();

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

#define fi first

#define se second

#define pb push_back

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

#define for1(i,n) for(int i=1;i<=n;i++)

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

#define all(x) x.begin(), x.end()

const int MAXN = 2e5 +5;



void fio(){

  ios::sync_with_stdio(0);

  cin.tie(0);

  cout.tie(0);

}



vector <vector <int> > adj(MAXN);

int n;

vector <int> in(MAXN), out(MAXN), vec;



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

  vec.pb(i);

  in[i] = vec.size()-1;

  for(auto j:adj[i])

    if(j!=p) dfs(j,i);

  out[i] = vec.size()-1;

}







int main(){

  fio();

  int q; cin>>n>>q;

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

    int u,v; cin>>u>>v;

    adj[u].pb(v);

    adj[v].pb(u);

    } 

  dfs(1);

  vector <LL> an(n+5);

  while(q--){

    LL u,x; cin>>u>>x;

    an[in[u]]+=x;

    an[out[u]+1]-=x;

  }

  for1(i,n)

    an[i]+=an[i-1];

  for1(i,n) 

    cout<<an[in[i]]<<" ";

  cout<<endl;

  return 0;

}




// Faster C++ solution for the same problem (measured speedup: 1.3099103882272713x):
#include <bits/stdc++.h>

using namespace std;



const int maxn = 2e5 + 3;



int n, q, a, b;

vector <int> graph[maxn];

int ar[maxn], ans[maxn];



void dfs(int i, int ansPar, int par){

    ans[i] = ansPar + ar[i];

    for (int u : graph[i])

        if (u != par)

            dfs(u, ans[i], i);

}



int main() {

    cin >> n >> q;

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

        cin >> a >> b;

        graph[a].push_back(b);

        graph[b].push_back(a);

    }

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

        cin >> a >> b;

        ar[a] += b;

    }

    dfs(1, 0, 0);

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

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

    cout << endl;

}