stablegradients/pie-gem5-pairs huggingface dataset:
// 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.2809146177873025x):
#include <bits/stdc++.h>

using namespace std;



const int MAX_N = 200 * 1000, MAX_Q = 200 * 1000;

vector<int> adjLis[MAX_N + 1];

int counter[MAX_N + 1];



void dfs(int preVer, int v) {

    int u;

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

        u = adjLis[v][i];

        if (u != preVer) {

            counter[u] += counter[v];

            dfs(v, u);

        }

    }

}



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(NULL);

    int N, Q, a[MAX_N], b[MAX_N], p[MAX_Q], x[MAX_Q];

    cin >> N >> Q;

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

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

        adjLis[a[i]].push_back(b[i]);

        adjLis[b[i]].push_back(a[i]);

    }

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

        cin >> p[j] >> x[j];

        counter[p[j]] += x[j];

    }

    dfs(0, 1);

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

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

    cout << counter[N] << '\n';

    return 0;

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

using namespace std;

typedef long long ll;

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



vector<int> to[200005];

ll ans[200005];



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

    for(int i:to[v]){

        if(i == p) continue; // 親ノードには戻らない

        ans[i] += ans[v];

        dfs(i,v);

    }

}



int main(){

    int N,Q;

    cin >> N >> Q;

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

        int a,b;

        cin >> a >> b;

        a--; b--;   // ０始まりのために-1

        to[a].push_back(b);

        to[b].push_back(a); // aがbの親とは限らないので双方向に辺を張る

    }

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

        int p;

        ll x;

        cin >> p >> x;

        p--;

        ans[p] += x;

    }



    dfs(0);



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

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

    }

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

    return 0;

}

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

using namespace std;

typedef long long ll;

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

#define INF (1LL<<50)

#define MOD 1000000007



typedef vector<vector<int>> Graph; 

vector<bool> seen;

vector<ll> counter,ADD;

void dfs(Graph &T,int num,ll cnt){

    seen[num]=true;

    counter[num] = cnt;

    for(int i=0;i<T[num].size();i++){

        if(seen[T[num][i]])continue;

        dfs(T,T[num][i],cnt+ADD[T[num][i]]);

    }

}



int main(){

    int N,Q;

    cin >> N >> Q;

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

    seen.resize(N+1,false);

    counter.resize(N+1,0);

    ADD.resize(N+1,0);

    rep(i,N-1){

        int a,b;

        cin >> a >> b;

        T[a].push_back(b);

        T[b].push_back(a);

    }

    rep(i,Q){

        ll p,x;

        cin >> p >> x;

        ADD[p]+=x;

    }

    dfs(T,1,ADD[1]);

    rep(i,N)cout << counter[i+1] << " ";

    cout << endl;

    return 0;

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

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

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

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

#define FOR(i, m, n) for(int i = m; i < n; ++i)

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

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

using namespace std;

typedef long long ll;

typedef pair<ll, ll> P;

const ll MOD = 1000000007;

const ll INF = 1000000000;



vector<int> G[200000];

vector<int> V;



void dfs(int v, int p) {

    for(int u : G[v]) {

        if(u==p) continue;

        V[u] += V[v];

        dfs(u, v);

    }

}



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);

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

    }

    V.resize(n);

    REP(i,q) {

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

        V[p] += x;

    }

    dfs(0,-1);

    REP(i,n) {

        if(i==n-1) cout << V[i] << endl;

        else cout << V[i] << " ";

    }

    return 0;

}

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

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

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

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

#define FOR(i, m, n) for(int i = m; i < n; ++i)

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

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

using namespace std;

typedef long long ll;

typedef pair<ll, ll> P;

const ll MOD = 1000000007;

const ll INF = 1000000000;



void dfs(int v, int p, vector<int> &ans, vector<vector<int>> &g) {

    for(int u : g[v]) {

        if(u==p) continue;

        ans[u] += ans[v];

        dfs(u, v, ans, g);

    }

}



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);

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

    vector<vector<int>> 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> ans(n,0);

    REP(i,q) {

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

        ans[p] += x;

    }

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

    REP(i,n) {

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

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

    }

    return 0;

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

using namespace std;



int N, Q;

vector<int> edges[200000];

int64_t num[200000];



void dfs(int i, int p){

    for(int j : edges[i]) if(j != p){

        num[j] += num[i];

        dfs(j, i);

    }

}



int main(){

    cin >> N >> Q;

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

        int a, b;

        cin >> a >> b;

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

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

    }

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

        int p, x;

        cin >> p >> x;

        num[p-1] += x;

    }

    dfs(0, -1);

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

    return 0;

}


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

#include <iostream>

#include <string.h>

#include <limits.h>

#include <string>

#include <vector>

#include <algorithm>

#include <map>

#include <set>



#ifndef ULLONG

typedef unsigned long long ULLONG;

#endif

#ifndef LLONG

typedef long long LLONG;

#endif

template <class _T> static _T tp_abs(const _T& a) {

	return ((a < 0) ? (a * -1) : a);

}

template <class _T> static _T tp_min(_T a, _T b) {

	return a < b ? a : b;

}

template <class _T> static _T tp_max(_T a, _T b) {

	return a > b ? a : b;

}

template<class _T> static void get1int(_T& a) {

	const char* fmt = " %d";

	if (sizeof(_T) == sizeof(long long)) {

		fmt = " %lld";

	}



	if (scanf(fmt, &a) < 0) {

		printf("g1int Error\n");

	}

}

template<class _T> static void get2int(_T& a, _T& b) {

	const char* fmt = " %d %d";

	if (sizeof(_T) == sizeof(long long)) {

		fmt = " %lld %lld";

	}



	if (scanf(fmt, &a, &b) < 0) {

		printf("g2int Error\n");

	}

}

template<class _T> static void get3int(_T& a, _T& b, _T& c) {

	const char* fmt = " %d %d %d";

	if (sizeof(_T) == sizeof(long long)) {

		fmt = " %lld %lld %lld";

	}



	if (scanf(fmt, &a, &b, &c) < 0) {

		printf("g3int Error\n");

	}

}

static void getstring(char* buff) {

	if (scanf(" %s", buff) < 0) {

		printf("getstr error!\n");

	}

}

static const long long MOD_NUM = 1000000007LL;



static void D2_task();



int main()

{

	D2_task();

	fflush(stdout);

	return 0;

}



class D2_data {

public:

	LLONG value = 0;

	bool add = false;

};

static void D2_dfs(std::vector<std::vector<int>>& graph, D2_data* tree, int now, int par)

{

//	if (tree[par].add) return;

//	tree[par].add = true;



	for (auto it = graph[now].begin(); it != graph[now].end(); it++) {

		if (*it == par) continue;

		tree[*it].value += tree[now].value;

		D2_dfs(graph, tree, *it, now);

	}

}



static void D2_task()

{

	int N, Q;

	get2int(N, Q);



	std::vector<std::vector<int>> graph(N);

	int a, b;

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

		get2int(a, b); a--; b--;

		graph[a].push_back(b);

		graph[b].push_back(a);

	}

	auto tree = new D2_data[N];



	int p, x;

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

		get2int(p, x); p--;

		tree[p].value += (LLONG)x;

	}

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

		D2_dfs(graph, tree, 0, -1);

	//}



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

		printf("%lld ", tree[i].value);

	}



	delete[] tree;

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

using namespace std;



int N, Q;

vector<int> edges[200000];

int64_t num[200000];



void dfs(int i, int p){

    for(int j : edges[i]) if(j != p){

        num[j] += num[i];

        dfs(j, i);

    }

}



int main(){

    cin >> N >> Q;

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

        int a, b;

        cin >> a >> b;

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

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

    }

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

        int p, x;

        cin >> p >> x;

        num[p-1] += x;

    }

    dfs(0, -1);

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

    return 0;

}


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


#include <stdio.h>

#include <iostream>

#include <string.h>

#include <limits.h>

#include <string>

#include <vector>

#include <algorithm>

#include <map>

#include <set>



#ifndef ULLONG

typedef unsigned long long ULLONG;

#endif

#ifndef LLONG

typedef long long LLONG;

#endif

template <class _T> static _T tp_abs(const _T& a) {

	return ((a < 0) ? (a * -1) : a);

}

template <class _T> static _T tp_min(_T a, _T b) {

	return a < b ? a : b;

}

template <class _T> static _T tp_max(_T a, _T b) {

	return a > b ? a : b;

}

template<class _T> static void get1int(_T& a) {

	const char* fmt = " %d";

	if (sizeof(_T) == sizeof(long long)) {

		fmt = " %lld";

	}



	if (scanf(fmt, &a) < 0) {

		printf("g1int Error\n");

	}

}

template<class _T> static void get2int(_T& a, _T& b) {

	const char* fmt = " %d %d";

	if (sizeof(_T) == sizeof(long long)) {

		fmt = " %lld %lld";

	}



	if (scanf(fmt, &a, &b) < 0) {

		printf("g2int Error\n");

	}

}

template<class _T> static void get3int(_T& a, _T& b, _T& c) {

	const char* fmt = " %d %d %d";

	if (sizeof(_T) == sizeof(long long)) {

		fmt = " %lld %lld %lld";

	}



	if (scanf(fmt, &a, &b, &c) < 0) {

		printf("g3int Error\n");

	}

}

static void getstring(char* buff) {

	if (scanf(" %s", buff) < 0) {

		printf("getstr error!\n");

	}

}

static const long long MOD_NUM = 1000000007LL;



static void D2_task();



int main()

{

	D2_task();

	fflush(stdout);

	return 0;

}



static void D2_dfs(std::vector<std::vector<int>>& graph, std::vector<LLONG>& tree, int now, int par)

{

	for (auto it = graph[now].begin(); it != graph[now].end(); it++) {

		if (*it == par) continue;

		tree[*it] += tree[now];

		D2_dfs(graph, tree, *it, now);

	}

}



static void D2_task()

{

	int N, Q;

	get2int(N, Q);



	std::vector<std::vector<int>> graph(N);

	int a, b;

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

		get2int(a, b); a--; b--;

		graph[a].push_back(b);

		graph[b].push_back(a);

	}

	

	std::vector<LLONG> tree(N, 0);

	int p, x;

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

		get2int(p, x); p--;

		tree[p] += (LLONG)x;

	}



	D2_dfs(graph, tree, 0, -1);



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

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

	}

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

vector<int> ans(200002, 0);



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

	for(int u: ki.at(v)){

		if(u == p) continue;

		ans.at(u) += ans.at(v);

		dfs(u, v);

	}

}



int main() {

	

	int n, q;

	cin >> n >> q;

	

	rep(i, n-1){

		int a, b;

		cin >> a >> b;

		a--;

		b--;

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

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

	}

	rep(i, q){

		int p, x;

		cin >> p >> x;

		p--;

		ans.at(p) += x;

	}

	

	dfs(0);

	

	rep(i, n){

		cout << ans.at(i) << " ";

	}

	cout << endl;

	return 0;

}

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

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

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

using namespace std;

typedef long long ll;



void dfs(vector<vector<int>> &g, int v, int p, vector<int> &c) {

	for(auto next_v: g[v]) {

		if(next_v == p) continue;

		c[next_v] += c[v];

		dfs(g, next_v, v, c);

	}

}



int main() {

	int n, q;

	cin >> n >> q;

	vector<vector<int>> 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> p(q), x(q), c(n);

	rep(i, q) {

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

		p[i]--;

	}

	rep(i, q) {

		c[p[i]] += x[i];

	}

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

	rep(i, n) printf("%d%c", c[i], (i == n-1) ? '\n' : ' ');

	return 0;

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

#include<vector>

#include<string>

#include<cmath>

#include<algorithm>

#include <numeric>

#include<map>

#include<unordered_map>

 

using namespace std;

using ll=long long;

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

#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)

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



struct tree{

    ll self;

    vector<ll> child;

    ll counter = 0;

};

tree t[200010];

bool visited[200010];

void score(ll c){

    visited[c] = true;

    rep(i, t[c].child.size()){

        ll leaf = t[c].child[i];

        if(visited[leaf])continue;

        t[leaf].counter += t[c].counter;

        score(leaf);

    }

}

int main(){

    ll n, q;

    cin >> n >> q;

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

        ll a, b;

        cin >> a >> b;

        t[a].child.push_back(b);

        t[b].child.push_back(a);

    }

    rep(i, q){

        ll p, x;

        cin >> p >> x;

        t[p].counter += x;

    }

    rep(i, 200010)visited[i] = false;



    score(1);

    for(int i = 1; i <= n; ++i)cout << t[i].counter << " ";

}

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

 

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

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

 

using namespace std;

using ll  = long long;

using pll = pair<ll, ll>;

 

const ll MOD  = 1e9+7;

const ll LINF = 1LL << 60;

const int INF = 1e9 + 7;



struct node{

    vector<ll> child;

    ll counter = 0;

};



vector<node> tree(200020);



void dfs(ll crnt_node, ll parent){

    tree[crnt_node].counter += tree[parent].counter;



    rep(i, tree[crnt_node].child.size()){

        ll next_node = tree[crnt_node].child[i];

        if(next_node == parent)continue;

        dfs(next_node, crnt_node);

    }

}



int main(){

    ll n, q;

    cin >> n >> q;



    rep(i, n-1){

        ll a, b;

        cin >> a >> b;

        a--, b--;



        tree[a].child.push_back(b);

        tree[b].child.push_back(a);

    }



    rep(i, q){

        ll p, x;

        cin >> p >> x;

        p--;



        tree[p].counter += x;

    }



    rep(i, tree[0].child.size()){

        ll next_node = tree[0].child[i];

        dfs(next_node, 0);

    }



    rep(i, n)cout << tree[i].counter << " ";

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

#include<vector>

#include<string>

#include<cmath>

#include<algorithm>

#include <numeric>

#include<map>

#include<unordered_map>

 

using namespace std;

using ll=long long;

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

#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)

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



struct tree{

    ll self;

    vector<ll> child;

    ll counter = 0;

};

tree t[200010];

bool visited[200010];

void score(ll c){

    visited[c] = true;

    rep(i, t[c].child.size()){

        ll leaf = t[c].child[i];

        if(visited[leaf])continue;

        t[leaf].counter += t[c].counter;

        score(leaf);

    }

}

int main(){

    ll n, q;

    cin >> n >> q;

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

        ll a, b;

        cin >> a >> b;

        t[a].child.push_back(b);

        t[b].child.push_back(a);

    }

    rep(i, q){

        ll p, x;

        cin >> p >> x;

        t[p].counter += x;

    }

    rep(i, 200010)visited[i] = false;



    score(1);

    for(int i = 1; i <= n; ++i)cout << t[i].counter << " ";

}

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

 

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

#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)

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



using namespace std;

using ll  = long long;

using pll = pair<ll, ll>;



const ll MOD  = 1e9 + 7;

const ll LINF = 1LL << 62;

const int INF = 1e9 + 7;



vector<vector<ll>> tree(200010);

vector<ll> point(200010, 0);



void dfs(ll crr, ll parent){

    rep(i, tree[crr].size()){

        if(tree[crr][i] == parent)continue;



        point[tree[crr][i]] += point[crr];

        dfs(tree[crr][i], crr);

    }

}



int main(){

    ll n, q;

    cin >> n >> q;



    rep(i, n-1){

        ll a, b;

        cin >> a >> b;



        a--, b--;

        tree[a].push_back(b);

        tree[b].push_back(a);

    }



    rep(i, q){

        ll p, x;

        cin >> p >> x;



        p--;

        point[p] += x;

    }



    dfs(0, 0);



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

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

using namespace std;



// 隣接行列を用いた幅優先探索 O(|V|^2)

int n;

vector<int> G[200000];

vector<int> d(200000), visited(200000); // 始点sから頂点iまでの最短距離をd[i]に記録

/*

* main関数からこれらを削除すること

* 隣接行列Mの行数と列数および最短距離dの要素数はnの最大値を整数で入力すること

*/



void bfs(int s) {

  queue<int> q;

  q.push(s);

  visited[s] = 1;

  // d[s] = 0;

  while(!q.empty()){

    int u = q.front();

    q.pop();

    for(int v = 0; v < G[u].size(); v++){

      if(visited.at(G[u][v]) == 0){

        d[G[u][v]] += d[u];

        visited.at(G[u][v]) = 1;

        /* if(M[u][v] == 0) continue;

        if(d[v] != 100000000) continue;

        d[v] = d[u] + 1;*/

        q.push(G[u][v]);

      }

    }

  }

}



int main() {

// 無向(有向)グラフの隣接リスト

  int q, u, v, p, x;

  

  cin >> n >> q;

  

  // vector<int> G[n]; // 頂点数がnのグラフを表す隣接リスト

  

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

    cin >> u >> v;

    u--;

    v--;

    G[u].push_back(v);

    G[v].push_back(u); // 有向グラフではこの行をコメントアウト

  }

  

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

    cin >> p >> x;

    d.at(p - 1) += x;

  }

  

  bfs(0);

  

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

    if(i) cout << " ";

    cout << d[i];

  }

  cout << endl;

}

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

using namespace std;



using ll = long long;



void dfs(vector<vector<int>> &G, int x, int p, ll keep, vector<ll> &counter) {

  counter[x] += keep;

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

    if (G[x][i] == p) continue;

    dfs(G, G[x][i], x, counter[x], counter);

  }

}



int main() {

  cin.tie(0);

  ios::sync_with_stdio(false);

  

  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<ll> counter(n, 0);

  

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

    ll p, x;

    cin >> p >> x;

    p--;

    counter[p] += x;

  }

  

  dfs(G, 0, -1, 0, counter);

  

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

    if (i) cout << " ";

    cout << counter[i];

  }

  cout << '\n';

}
// Slower C++ solution:
// 嘘解法か判断する用

#include <bits/stdc++.h>

using namespace std;



// 隣接行列を用いた幅優先探索 O(|V|^2)

int n;

vector<int> G[200000];

vector<int> d(200000), visited(200000); // 始点sから頂点iまでの最短距離をd[i]に記録

/*

* main関数からこれらを削除すること

* 隣接行列Mの行数と列数および最短距離dの要素数はnの最大値を整数で入力すること

*/



void bfs(int s) {

  queue<int> q;

  q.push(s);

  visited[s] = 1;

  // d[s] = 0;

  while(!q.empty()){

    int u = q.front();

    q.pop();

    for(int v = 0; v < G[u].size(); v++){

      if(visited.at(G[u][v]) == 0){

        d[G[u][v]] += d[u];

        visited.at(G[u][v]) = 1;

        /* if(M[u][v] == 0) continue;

        if(d[v] != 100000000) continue;

        d[v] = d[u] + 1;*/

        q.push(G[u][v]);

      }

    }

  }

}



int main() {

// 無向(有向)グラフの隣接リスト

  int q, u, v, p, x;

  

  cin >> n >> q;

  

  // vector<int> G[n]; // 頂点数がnのグラフを表す隣接リスト

  

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

    cin >> u >> v;

    u--;

    v--;

    G[u].push_back(v);

    G[v].push_back(u); // 有向グラフではこの行をコメントアウト

  }

  

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

    cin >> p >> x;

    d.at(p - 1) += x;

  }

  

  bfs(0);

  

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

    if(i) cout << " ";

    cout << d[i];

  }

  cout << endl;

}


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

using namespace std;



using ll = long long;



void dfs(vector<vector<int>> &G, int x, int p, ll keep, vector<ll> &counter) {

  counter[x] += keep;

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

    if (G[x][i] == p) continue;

    dfs(G, G[x][i], x, counter[x], counter);

  }

}



int main() {

  cin.tie(0);

  ios::sync_with_stdio(false);

  

  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<ll> counter(n, 0);

  

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

    ll p, x;

    cin >> p >> x;

    p--;

    counter[p] += x;

  }

  

  dfs(G, 0, -1, 0, counter);

  

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

    if (i) cout << " ";

    cout << counter[i];

  }

  cout << '\n';

}