stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <vector>

#include <algorithm>

using namespace std;

template <class T>

inline bool chmax(T &a, T b) {

  if (a < b) {

    a = b;

    return 1;

  }

  return 0;

}



typedef long long ll;



vector<ll> to[200005];

vector<ll> ans;



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

  for (auto v : to[i]) {

    if (p == v) continue;

    ans[v] += ans[i];

    dfs(v, i);

  }

}



int main() {

  int n, q;

  cin >> n >> q;



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

    ll a, b;

    cin >> a >> b;

    a--;

    b--;

    to[a].push_back(b);

    to[b].push_back(a);

  }

  ans.resize(n);

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

    ll p, x;

    cin >> p >> x;

    ans[p-1] += x;

  }

  dfs(0);

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

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

  }

  cout << endl;

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 6.39971959325585x):
#include <iostream>

#include <vector>

#include <algorithm>

using namespace std;

template <class T>

inline bool chmax(T &a, T b) {

  if (a < b) {

    a = b;

    return 1;

  }

  return 0;

}



typedef long long ll;

ll MOD = 1000000007;



// a^p

// 2^3 = 2 * 2^2

// 2^2 = 2 * (2^1)

// 2^1 = 2

ll modpow(ll a, ll p, ll mod) {

  if (p == 0) return 1;



  if (p % 2 == 0) {

    ll half = modpow(a, p / 2, mod) % mod;

    return half * half % mod;

  } else {

    return a * modpow(a, p - 1, mod) % mod;

  }

}



// nCa を求める

ll modCombination(ll n, ll a, ll mod) {

  if (n - a < a) {

    return modCombination(n, n - a, mod);

  }



  ll denominator = 1;  // 分母

  ll numerator = 1;    // 分子



  for (ll i = 0; i < a; i++) {

    denominator *= a - i;

    numerator *= n - i;

    denominator %= mod;

    numerator %= mod;

  }



  return numerator * modpow(denominator, mod - 2, mod) % mod;

}



void dfs(vector<vector<ll>> &graph, vector<ll> &counter, vector<bool> &visited, ll parentCounter, ll current) {

  // cout << current << endl;

  visited[current] = true;

  counter[current] += parentCounter;



  for (auto v : graph[current]) {

    if (v == false) continue;

    if (visited[v] == true) continue;



    dfs(graph, counter, visited, counter[current], v);

  }

}



int main() {

  ll N, Q;

  cin >> N >> Q;

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



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

    ll a, b;

    cin >> a >> b;

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

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

  }



  vector<ll> counter(N, 0);

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

    ll p, x;

    cin >> p >> x;

    counter[p-1] += x;

  }



  vector<bool> visited(N, false);

  dfs(graph, counter, visited, 0, 0);



  for (auto p : counter) {

    cout << p << " ";

  }

  cout << endl;



  return 0;

}
// Slower C++ solution:
#include <iostream>

#include <vector>

#include <algorithm>

using namespace std;

template <class T>

inline bool chmax(T &a, T b) {

  if (a < b) {

    a = b;

    return 1;

  }

  return 0;

}



typedef long long ll;



vector<ll> to[200005];

vector<ll> ans;



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

  for (auto v : to[i]) {

    if (p == v) continue;

    ans[v] += ans[i];

    dfs(v, i);

  }

}



int main() {

  int n, q;

  cin >> n >> q;



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

    ll a, b;

    cin >> a >> b;

    a--;

    b--;

    to[a].push_back(b);

    to[b].push_back(a);

  }

  ans.resize(n);

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

    ll p, x;

    cin >> p >> x;

    ans[p-1] += x;

  }

  dfs(0);

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

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

  }

  cout << endl;

  return 0;

}


// Faster C++ solution for the same problem (measured speedup: 6.39971959325585x):
#include <iostream>

#include <vector>

#include <algorithm>

using namespace std;

template <class T>

inline bool chmax(T &a, T b) {

  if (a < b) {

    a = b;

    return 1;

  }

  return 0;

}



typedef long long ll;

ll MOD = 1000000007;



// a^p

// 2^3 = 2 * 2^2

// 2^2 = 2 * (2^1)

// 2^1 = 2

ll modpow(ll a, ll p, ll mod) {

  if (p == 0) return 1;



  if (p % 2 == 0) {

    ll half = modpow(a, p / 2, mod) % mod;

    return half * half % mod;

  } else {

    return a * modpow(a, p - 1, mod) % mod;

  }

}



// nCa を求める

ll modCombination(ll n, ll a, ll mod) {

  if (n - a < a) {

    return modCombination(n, n - a, mod);

  }



  ll denominator = 1;  // 分母

  ll numerator = 1;    // 分子



  for (ll i = 0; i < a; i++) {

    denominator *= a - i;

    numerator *= n - i;

    denominator %= mod;

    numerator %= mod;

  }



  return numerator * modpow(denominator, mod - 2, mod) % mod;

}



void dfs(vector<vector<ll>> &edges, vector<ll> &counter, vector<bool> &visited, ll parentCounter, ll current) {

  visited[current] = true;

  counter[current] += parentCounter;



  for (auto v : edges[current]) {

    if (v == false) continue;

    if (visited[v] == true) continue;



    dfs(edges, counter, visited, counter[current], v);

  }

}



int main() {

  ll N, Q;

  cin >> N >> Q;

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



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

    ll a, b;

    cin >> a >> b;

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

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

  }



  vector<ll> counter(N, 0);

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

    ll p, x;

    cin >> p >> x;

    counter[p-1] += x;

  }



  vector<bool> visited(N, false);

  dfs(edges, counter, visited, 0, 0);



  for (auto p : counter) {

    cout << p << " ";

  }

  cout << endl;



  return 0;

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

using namespace std;



long long n, q;

vector<long long> edge[200005], ans;

vector<bool> used;

queue<long long> qu;



void solve();



int main() {

  cin >> n >> q;

  used.resize(n, 0);

  ans.resize(n, 0);

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

    long long a, b;

    cin >> a >> b;

    --a, --b;

    edge[a].push_back(b);

    edge[b].push_back(a);

  }

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

    long long p, x;

    cin >> p >> x;

    ans[--p] += x;

  }

  solve();

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

    if(i != 0) cout << " ";

    cout << ans[i];

  }

  cout << endl;

  return 0;

}



void solve() {

  qu.push(0);

  while(!qu.empty()) {

    long long now = qu.front();

    qu.pop();

    used[0] = 1;

    for(int i = 0; i < (int)edge[now].size(); ++i)

      if(!used[edge[now][i]]) {

        long long nextp = edge[now][i];

        used[nextp] = 1;

        ans[nextp] += ans[now];

        qu.push(nextp);

      }

  }

}

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

using namespace std;



int n, q;

vector<vector<int>> g;

vector<int> sum;



void dfs(int now = 0, int par = -1);



int main() {

  cin >> n >> q;

  g.resize(n);

  sum.assign(n, 0);

  for (int i = 1; i < n; ++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;

    sum[--a] += b;

  }

  dfs();

  for (int i = 0; i < n; ++i) cout << sum[i] << " \n"[i == n - 1];

  return 0;

}



void dfs(int now, int par) {

  if (par >= 0) sum[now] += sum[par];

  for (auto to : g[now])

    if (to != par) dfs(to, now);

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

}


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

    }

 

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

    }

}




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

    }

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

}

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

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

}

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

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

	}

}

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

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

		int a, b;

		cin >> a >> b;

		G[a].push_back(b);

		G[b].push_back(a);

	}

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

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

		int a, b;

		cin >> a >> b;

		dist[a] = dist[a] +b;

	}

	queue<int> que;

	vector<bool> point(N + 1, 0);

	que.push(1);

	point[1] = true;

	while (!(que.empty())) {

		int v = que.front();

		que.pop();

		for (int nv : G[v]) {

			if (point[nv] == true) {

				continue;

			}

			point[nv] = true;

			dist[nv] = dist[v] +dist[nv];

			que.push(nv);

		}

	}

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

		cout << dist[i] << " ";

	}

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

	}

}

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

	}

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

}


// Faster C++ solution for the same problem (measured speedup: 1.1275404509827531x):
// -----------------------------------

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

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

  }

}

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

  }

}