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

using namespace std;



typedef long long ll;

typedef long double ld;

void fast()

{

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

}

const ll N=2e5 + 5;

const ll mod=1e9 + 7;

vector<ll> adj[N];

vector<ll> add(N,0);

vector<bool>visited(N,false);



void dfs(ll src,ll parent,ll val)

{

    visited[src]=true;

    add[src] = add[src] + val;

    for(ll i=0;i<adj[src].size();i++)

    {

        ll v=adj[src][i];

        if(v==parent)

            continue;

        dfs(v,src,add[src]);

    }

}

int main()

{

    fast();

    ll n,q;

    cin>>n>>q;



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

    {

        ll u,v;

        cin>>u>>v;

        u--;v--;

        adj[u].push_back(v);

        adj[v].push_back(u);

    }



    while(q-->0)

    {

        ll v,val;

        cin>>v>>val;

        v--;

        add[v]+=val;

    }





    dfs(0,-1,0);

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

        cout<<add[i]<<" ";

}


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

using namespace std;

using ll = long long;

 

typedef pair<int,int> P;

struct edge{int to, id;};

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

#define mod 1000000007

 

using graph = vector<vector<ll>>;

int jikan;

bool seen[200010];

ll sum[200010];

ll ans[200010];

void dfs(const graph &G, int v, ll parent, ll val){

    //seen[v] = true;

    //root[v].push_back(v);

    sum[v] += val;

 

    for(auto next_v : G[v]){

        //ans[next_v] = v+1;

        //first[next_v] = jikan;

        //ans[next_v] += ans[v];

 

        if (next_v == parent) continue;

        dfs(G, next_v,v,sum[v]);

      //root[v].push_back(next_v);

      /*for(auto hoge : root[next_v]){

        root[v].push_back(hoge);

      }*/

    }

}

 

int main(){

    ll n,q;

    cin >> n >> q;

    graph g(n);

    graph root(n);

  ll ans[n];

    rep(i,n){

        seen[i] = false;

      ans[i] = 0;

    }

    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 a,b;

        cin >> a >> b;

        sum[a-1] += b;

    }

    dfs(g,0,-1,0);

    rep(i,n){

        if(i < n-1) cout << sum[i] << ' ';

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

    }

 

}

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

using namespace std;

using ll = long long;

using P = pair<int, int>;

ll MOD = 1e9+7;

int n;

 map<int, int> m;

vector<bool> used(2*100000+10);

vector<vector<int>> g(2*100000+10);

vector<int> ans(2*100000 + 10);

void dfs(int s, int prev)

{

    used[s] = true;

    for(int i = 0; i < g[s].size(); i++)

    {

        int next = g[s][i];

        if(used[next]) continue;

        ans[next] = prev + m[next];

        dfs(next, ans[next]);

    }

}



int main()

{

    int q;

    cin >> n >> q;

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

    {

        int a, b;

        cin >> a >> b;

        g[a].push_back(b);

        g[b].push_back(a);

    }

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

    {

        ans[i] = 0;

        used[i] = false;

    }

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

    {

        int a, b;

        cin >> a >> b;

        if(m.count(a) == 0) m.insert(P(a,b));

        else m[a] += b;

    }

    ans[1] = m[1];

    dfs(1, ans[1]);

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

    {

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

    }

}




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

using namespace std;

int main()

{

    int n, q;

    cin >> n >> q;

    vector<vector<int>> g(n);

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

    {

        int a, b;

        cin >> a >> b;

        a--;b--;

        g[a].push_back(b);

        g[b].push_back(a);

    }

    vector<int> add(n, 0);

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

    {

        int p, x;

        cin >> p >> x;

        p--;

        add[p] += x;

    }

    vector<int> ans(n);

    function<void(int, int, int)> dfs = [&](int v, int pre, int sum)

    {

        sum += add[v];

        ans[v] = sum;

        for(int i = 0; i < (int)g[v].size(); i++)

        {

            int nx = g[v][i];

            if(nx != pre)

            {

                dfs(nx, v, sum);

            }

        }

    };

    dfs(0, -1, 0);

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

    {

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

    }

}




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

#include<vector>

#include<algorithm>



using namespace std;



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



int cost[200000];

int ans[200000];

vector<int> g[200000];



void func(int y, int count){

    if (ans[y] != -1) {

        return;

    }

    ans[y] = count;

    // cout << ans[y] << endl;

    rep(i, g[y].size()){

        func(g[y][i], count + cost[g[y][i]]);

    }

    

}



int main(){

    int n, q;

    cin >> n >> q;

    

    rep(i, n-1){

        int a, b;

        cin >> a >> b;

        a--;

        b--;

        g[a].push_back(b);

        g[b].push_back(a);

    }

    rep(i, q){

        int p, x;

        cin >> p >> x;

        p--;

        cost[p] += x;

    }

    fill(ans, ans + n, -1);

    func(0, cost[0]);

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

    cout << endl;

}

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

#include<algorithm>

#include<string>

#include<vector>

#include<cstdlib>

#include<queue>



using namespace std;



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

#define P pair<int, int>



int main(){

    int n, q;

    cin >> n >> q;

    int a, b;

    vector<int> g[n];

    rep(i, n - 1) {

        cin >> a >> b;

        a--; b--;

        g[a].push_back(b);

        g[b].push_back(a);

    }

    int p, x;

    int count[n];

    fill(count, count + n, 0);

    rep(i, q) {

        cin >> p >> x;

        p--;

        count[p] += x;

    }

    int ans[n];

    fill(ans, ans + n, -1);

    ans[0] = count[0];

    queue<P> que;

    que.push(P(0, ans[0]));

    while(!que.empty()){

        P p = que.front();

        int e = p.first;

        int c = p.second;

        que.pop();

        rep(i, g[e].size()){

            int e1 = g[e][i];

            if (ans[e1] == -1){

                ans[e1] = c + count[e1];

                que.push(P(e1, ans[e1]));

            }

        }

    }

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

    cout << endl;

}


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

#include <cstdio>

#include <vector>

using namespace std;



vector<vector<long long> > G(200000);

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

void dfs(long long i , long long p){

    if(G[i].size() == 1 and i != 0){

        //printf("G[%lld]\n", i);

        return;

    }

    for(long long v = 0; v < G[i].size(); v++){

        if(p == G[i][v]){

            continue;

        }

        counter[G[i][v]] += counter[i];

        dfs(G[i][v], i);

    }

    //return;

}

int main(){

    long long n ,q;

    cin >> n >> q;



    vector<vector<long long> > children(n);

    

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

        long long a, b;

        cin >> a >> b;

        a -= 1;

        b -= 1;

        

        children[a].push_back(b);

        G[a].push_back(b);

        G[b].push_back(a);

    }



    

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

        long long p, x;

        cin >> p >> x;

        p -= 1;

        counter[p] += x;



    }



    /*for(long long i = 0; i < n; i++){

        for(long long j = 0; j < children[i].size(); j++){

            counter[children[i][j]] += counter[i];

        }

    }*/



    dfs(0, -1);



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

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

    }

    printf("\n");



    return 0;

}

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

#include <cstdio>

#include <vector>

using namespace std;



using Graph = vector<vector<long long> >;

Graph G;



long long n, q;

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

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



void dfs(long long v, long long p){

    if(p != -1) ans[v] += ans[p];

    ans[v] += cnt[v];



    for(auto next : G[v]){

        if(next == p) continue;

        dfs(next, v);

    }

}





int main(){

    cin >> n >> q;

    G.assign(n, vector<long long>());



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

        long long a, b;

        cin >> a >> b;

        a--, b--;

        G[a].push_back(b);

        G[b].push_back(a);

    }



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

        long long p, x;

        cin >> p >> x;

        cnt[p-1] += x;

    }



    dfs(0, -1);



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

        if(i != n-1) printf("%lld ", ans[i]);

        else printf("%lld\n", ans[i]);

    }

    return 0;

}

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

using namespace std;

#define REP(i,a) for(int i = 0; i < (a);i++)

#define ALL(a) (a).begin(),(a).end()

typedef long long ll;

typedef pair<int, int> P;

const int INF = 1e9;

const int MOD = 1e9 + 7;

using Graph = vector < vector<int>>;

long int sum[200020] = {};

int main() {

	int N, Q;

	cin >> N >> Q;

	Graph G(N+10);

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

		int a, b;

		cin >> a >> b;

		G[b].push_back(a);

		G[a].push_back(b);

	}

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

		int a, b;

		cin >> a >> b;

		sum[a] = b + sum[a];

	}

	queue<int> que;

	vector<int> s(200003);

	que.push(1);

	s[1] = 1;

	while (!que.empty()) {

		int v = que.front();

		que.pop();

		for (int nv : G[v]) {

			if (s[nv] == 1)

				continue;

			que.push(nv);

			s[nv] = 1;

			sum[nv] = sum[nv] + sum[v];

		}

	}

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

			cout << sum[i] << " ";

	}

}

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

using namespace std;

#define REP(i,a) for(int i = 0; i < (a);i++)

#define ALL(a) (a).begin(),(a).end()

typedef long long ll;

typedef pair<int, int> P;

const int INF = 1e9;

const int MOD = 1e9 + 7;

using Graph = vector < vector<int>>;

long int sum[200020] = {};

/*第二引数で第一引数を割ったときの切り上げの計算*/

long long int maxtime(long long int x) {

	return(x + 9) / 10 * 10;



}

/*最大公約数*/

long long int lcm(long long int number1, long long int number2) {

	long long int m = number1;

	long long int n = number2;



	if (number2 > number1) {

		m = number2;

		n = number1;

	}

	long long int s = -1;

	while (s != 0) {

		s = m % n;

		m = n;

		n = s;

	}

	return m;

}

/*最大公倍数*/

long long int gcd(long long int number1, long long int number2) {

	long long int m = number1;

	long long int n = number2;

	return m / lcm(m, n) * n;

}



int main() {

	int N, Q;

	cin >> N >> Q;

	vector<vector<int>> G(N + 1);

	vector<int> value(N+1);

	vector<int> look(N + 1, 0);

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

		int a, b;

		cin >> a >> b;

		G[a].push_back(b);

		G[b].push_back(a);

	}

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

		int a, b;

		cin >> a >> b;

		value[a] = value[a] + b;

	}

	queue<int> q;

	q.push(1);

	look[1] = 1;

	while (!q.empty()) {

		int a = q.front();

		q.pop();

		for (auto i : G[a]) {

			if (look[i] != 0) {

				continue;

			}

			else {

				look[i] = 1;

				q.push(i);

				value[i] = value[i] + value[a];

			}

		}

	}

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

		cout << value[i] << " ";

	}

}

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



using namespace std;





vector<int> graph[200000];

vector<int> counter(200000, 0);

vector<int> ans(200000, 0);

void dfs (int n, int c) {

  ans[n] = c+counter[n];

  for (auto t : graph[n]) {

    dfs(t, ans[n]);

  }

}

int main() {

  cin.tie(nullptr); ios::sync_with_stdio(false);



  int N,Q; cin>>N>>Q;

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

    int a,b; cin>>a>>b;

    a--,b--;

    graph[a].push_back(b);

  }

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

    int p,x; cin>>p>>x;

    p--;

    counter[p] += x;

  }

  set<int> in;

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

    in.insert(i);

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

    for (auto ee : graph[i]) {

      in.erase(ee);

    }

  }

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

    if (in.count(i)==0)

      continue;

    dfs(i, 0);

  }

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

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

  }

  cout << endl;



  return 0;

}


// Optimized solution to the same problem (faster):
// -----------------------------------

// Author     : MatsuTaku

// Country    : Japan

// Created    : 04/16/20 07:31:34

// -----------------------------------



#include <bits/stdc++.h>



using namespace std;

using ll = long long;





vector<int> graph[(int)2e5];

vector<int> cnt((int)2e5);

void dfs(int s, int p, int c) {

  c+= cnt[s];

  cnt[s] = c;

  for (auto t:graph[s]) {

    if (t==p) continue;

    dfs(t, s, c);

  }

}



int main() {

  cin.tie(nullptr); ios::sync_with_stdio(false);



  int n,q; cin>>n>>q;

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

    int a,b; cin>>a>>b; a--; b--;

    graph[a].push_back(b);

    graph[b].push_back(a);

  }

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

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

    cnt[p] += x;

  }

  dfs(0, -1, 0);

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

    cout << cnt[i] << " ";

  cout << endl;



  return 0;

}


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

using namespace std;



int N;

vector<int> cnt; 

vector<int> G[200010];



void dfs(int v, int p = -1){ // pはvの親

  for(int nv : G[v]){

    if(nv == p) continue;

    cnt[nv] += cnt[v];

    dfs(nv, v);

  }

}



int main(){

  int Q; cin >> N >> Q; 

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

    int a, b; cin >> a >> b;

    a--; b--; //0スタートの木に変える

    G[a].push_back(b);

    G[b].push_back(a);

  }

  cnt.resize(N);

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

    int p, x; cin >> p >> x;

    p--;

    cnt[p] += x; 

  }

  dfs(0); //index0が根

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

    cout << cnt[i] << " ";

  }

}

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

using namespace std;

using Graph = vector<vector<int>>;



vector<int> cnt; 



void dfs(Graph &G,int v, int p = -1){ // pはvの親

  for(int nv : G[v]){

    if(nv == p) continue;

    cnt[nv] += cnt[v];

    dfs(G, nv, v);

  }

}



int main(){

  int N; int Q; cin >> N >> Q; 

  Graph G(N);

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

    int a, b; cin >> a >> b;

    a--; b--; //0スタートの木に変える

    G[a].push_back(b);

    G[b].push_back(a);

  }

  cnt.resize(N);

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

    int p, x; cin >> p >> x;

    p--;

    cnt[p] += x; 

  }

  dfs(G, 0); //index0が根

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

    cout << cnt[i] << " ";

  }

}




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

    #include<stdio.h>

    //#include <bits/stdc++.h>

    #include<vector>

    #include<float.h>

    #include<iomanip>

    #include<algorithm>

    #include<string>

    #include<cstring>

    #include<math.h>

    #include<cmath>

    #include<sstream>

    #include<set>

    #include<map>

    #include<queue>

    #include <cassert>

    #include <cmath>



    #define INF 1e9

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

    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)

    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;

    #define vec(type,n) vector<type>(n)

    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))



    using namespace std;

    using ll = long long;

    using Graph = vector<vector<int>>;

    using P = pair<int,int>;





    vector<int> ans;

    vector<int> to[200005];

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

        for(auto nv : to[v]){

            if(nv == p)continue;

            ans[nv] += ans[v];

            dfs(nv,v);

        }

    }

    

    int main(){

        int n,q;cin>>n>>q;

        ans.resize(n);

        rep(i,n-1){

            int a,b;cin>>a>>b;

            a--;b--;

            to[a].push_back(b);

            to[b].push_back(a);

        }

        rep(i,q){

            int p,x;cin>>p>>x;

            p--;

            ans[p] += x;

        }

        //rep(i,n)c[i] = mp[0];

        dfs(0);

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

    }

    


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

#include<stdio.h>

//#include <bits/stdc++.h>

#include<vector>

#include<float.h>

#include<iomanip>

#include<algorithm>

#include<string>

#include<cstring>

#include<math.h>

#include<cmath>

#include<sstream>

#include<set>

#include<map>

#include<queue>

#include <cassert>

#include <cmath>

#include<cstdint>



#define INF 1e9

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

#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)

#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;

#define vec(type,n) vector<type>(n)

#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

#define ALL(a)  (a).begin(),(a).end()



using namespace std;

using ll = long long;

using Graph = vector<vector<int>>;

using P = pair<int,int>;



int n,q;

vector<bool>seen(n);

void dfs(const Graph &G,int v,vector<int>&cnt,int p = -1){

    seen[v] = true;

    for(auto nv : G[v]){

        if(nv==p)continue;

        if(seen[nv])continue;

        cnt[nv] += cnt[v];

        dfs(G,nv,cnt,v);

    }

}



int main(){

    cin>>n>>q;

    Graph G(n);

    rep(i,n-1){

        int a,b;cin>>a>>b;

        a--;b--;

        G[a].push_back(b);

        G[b].push_back(a);

    }

    vector<int>cnt(n,0);

    rep(i,q){

        int p,x;cin>>p>>x;

        p--;

        cnt[p] += x;

    }

    seen.assign(n,false);

    dfs(G,0,cnt);

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

}




// 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++)

using namespace std;



using ll = long long;



bool done[200000];

int cnt[200000];

vector<int> edge[200000];



void dfs(int v) {

    done[v] = true;

    rep(i, edge[v].size()) {

        int j = edge[v][i];

        if (done[j]) continue;

        cnt[j] += cnt[v];

        dfs(j);

    }

    return;

}



int main() {

    rep(i, 200000) done[i] = false;

    rep(i, 200000) cnt[i] = 0;

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

    cin >> N >> Q;

    rep(i, N - 1) {

        cin >> a >> b;

        a--;

        b--;

        edge[a].push_back(b);

        edge[b].push_back(a);

    }

    rep(i, Q) {

        cin >> p >> x;

        cnt[p - 1] += x;

    }

    dfs(0);

    rep(i, N) cout << cnt[i] << " ";

    cout << endl;

}

// 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;



int main() {

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

    cin >> N >> Q;

    vector<vector<int>> edge(N, vector<int>(0));

    rep(i, N - 1) {

        cin >> a >> b;

        edge[a - 1].push_back(b - 1);

        edge[b - 1].push_back(a - 1);

    }

    vector<int> px(N, 0), ans(N, 0);

    rep(i, Q) {

        cin >> p >> x;

        px[p - 1] += x;

    }

    queue<pair<int, int>> q;

    q.push(make_pair(0, px[0]));

    vector<bool> done(N, false);

    while (q.size() > 0) {

        auto c = q.front();

        q.pop();

        ans[c.first] = c.second;

        done[c.first] = true;

        rep(i, edge[c.first].size()) {

            int d = edge[c.first][i];

            if (done[d]) continue;

            q.push(make_pair(d, c.second + px[d]));

        }

    }

    rep(i, N) {

        cout << ans[i];

        if (i == N - 1) cout << endl;

        else cout << " ";

    }

}

// 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++)

using namespace std;

typedef long long ll;



vector<int> to[200005];

vector<int> ans;



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

    for (int u : to[v]) {

        if (u == p) continue;

        ans[u] += ans[v];

        dfs(u,v);

    }

}



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>> graph;

vector<int> values;



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

    for (int v : graph[x]) {

        if (v == p) continue;

        values[v] += values[x];

        dfs(v,x);

    }

}



int main() {

    int n, q;

    cin >> n >> q;

    graph.resize(n);

    values.resize(n);

    rep(i,n-1) {

        int a, b;

        cin >> a >> b;

        --a; --b;

        graph[a].push_back(b);

        graph[b].push_back(a);

    }

    rep(i,q) {

        int p, x;

        cin >> p >> x;

        --p;

        values[p] += x;

    }

    dfs(0);

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

        if (i != n-1) printf("%d ", values[i]);

        else printf("%d\n",values[i]);

    }

    return 0;

}

// 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++)

using namespace std;

typedef long long ll;



vector<int> to[200005];

vector<int> ans;



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

    for (int u : to[v]) {

        if (u == p) continue;

        ans[u] += ans[v];

        dfs(u,v);

    }

}



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) printf("%d ", ans[i]);

        else printf("%d\n", ans[i]);

    }

    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>> graph;

vector<int> values;



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

    for (int v : graph[x]) {

        if (v == p) continue;

        values[v] += values[x];

        dfs(v,x);

    }

}



int main() {

    int n, q;

    cin >> n >> q;

    graph.resize(n);

    values.resize(n);

    rep(i,n-1) {

        int a, b;

        cin >> a >> b;

        --a; --b;

        graph[a].push_back(b);

        graph[b].push_back(a);

    }

    rep(i,q) {

        int p, x;

        cin >> p >> x;

        --p;

        values[p] += x;

    }

    dfs(0);

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

        if (i != n-1) printf("%d ", values[i]);

        else printf("%d\n",values[i]);

    }

    return 0;

}

// Fastest known solution for this problem: