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

#include <vector>

using namespace std;

vector<int> v[200000];

int cnt[200000];

void cal(int x, int y){

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

        int z = v[x][i];

        if(z != y){

            cnt[z] += cnt[x];

            cal(z, x);

        }

    }

}

int main(void){

    int n, q;

    cin >> n >> q;

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

        int a, b;

        cin >> a >> b;

        a--;

        b--;

        v[a].push_back(b);

        v[b].push_back(a);

    }

    fill(cnt, cnt+n, 0);

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

        int p, x;

        cin >> p >> x;

        cnt[--p] += x;

    }

    cal(0, -1);

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

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

    }

    cout << endl;

}


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

#include <vector>

using namespace std;

int n, k;

vector< vector<int> > edg;

vector<int> cnt;

void cal(int v, int c, int p){

    cnt[v] += c;

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

        int w = edg[v][i];

        if(w == p)continue;

        cal(w, cnt[v], v);

    }

}

int main(void){

    cin >> n >> k;

    edg.assign(n, vector<int>());

    cnt.assign(n, 0);

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

        int a, b;

        cin >> a >> b;

        a--;

        b--;

        edg[a].push_back(b);

        edg[b].push_back(a);

    }

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

        int p, x;

        cin >> p >> x;

        cnt[--p] += x;

    }

    cal(0, 0, -1);

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

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

        

    }

    cout << endl;

}


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

using namespace std;

typedef long long ll;

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

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

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



int N;

int C[200001];

int X[200001];

vector<int> E[200001];

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

	int k = c + X[p];

	C[p] = k;

	for (int to : E[p]) {

		if (to != prev) dfs(to, p, k);

	}

}





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;

		E[a].pb(b);

		E[b].pb(a);

	}

	rep(i, Q) {

		int p, x;

		cin >> p >> x;

		X[p] += x;

	}

	dfs(1, 0, 0);



	rep1(i, N) cosp(C[i]);



	Would you please return 0;

}

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

#include<cstdio>



using namespace std;

typedef long long ll;

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

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

#define co(x) cout << (x) << "\n"

#define cosp(x) cout << (x) << " "

#define ce(x) cerr << (x) << "\n"

#define cesp(x) cerr << (x) << " "

#define pb push_back

#define mp make_pair

#define Would

#define you

#define please



//有向気味でもなぜかよさそうと解説放送で聞いたけど



int N;

int C[200001];

int E[200001];

int next[200001];

int H[200001];

void dfs(int p, int c) {

	C[p] = c + C[p];

	for (int i = H[p]; i; i = next[i]) {

		dfs(E[i], C[p]);

	}

}



const int cm = 1 << 17;

char cn[cm], * ci = cn + cm, ct;

inline char getcha() {

	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }

	return *ci++;

}

inline int getint() {

	int A = 0;

	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';

	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';

	return A;

}



const int dm = 1 << 21;

char dn[dm], * di = dn;

inline void putint(int X) {

	if (X == 0) {

		*di++ = '0';

		*di++ = ' ';

		return;

	}

	int keta = 0;

	char C[10];

	while (X) {

		*(C + keta) = '0' + X % 10;

		X /= 10;

		keta++;

	}

	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));

	*di++ = ' ';

}



int main() {

	//cin.tie(0);

	//ios::sync_with_stdio(false);





	int N = getint(), Q = getint();

	int k = 1;

	rep(i, N - 1) {

		int a = getint(), b = getint();

		E[k] = b;

		next[k] = H[a];

		H[a] = k++;

	}

	rep(i, Q) {

		int p = getint(), x = getint();

		C[p] += x;

	}

	dfs(1, 0);



	rep1(i, N) putint(C[i]);



	fwrite(dn, 1, di - dn, stdout);



	Would you please return 0;

}

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

#include <vector>



using namespace std;

vector<int> G[200005];

int seen[200005] = {0};

int ans[200005] = {0};



void dfs(int s) {

    seen[s] = 1;

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

        int n = G[s][i];



        if (seen[n] == 1)

            continue;



        ans[n] += ans[s];

        dfs(n);

    }

}



int main() {

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



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

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

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

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

    }



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

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

        ans[p-1] += x;

    }



    dfs(0);



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

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



    cout << endl;



    return 0;

}

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

#include <vector>



using namespace std;



int seen[200005] = {0};

int ans[200005] = {0};



void dfs(vector<vector<int> > &G, int s) {

    seen[s] = 1;

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

        int n = G[s][i];



        if (seen[n] == 1)

            continue;



        ans[n] += ans[s];

        dfs(G, n);

    }

}



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;

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

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

    }



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

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

        ans[p-1] += x;

    }



    dfs(G, 0);



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

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



    cout << endl;



    return 0;

}

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

using namespace std;



long long n, q;



const long long N = 200010;

vector<long long> G[N];

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

vector<bool> seen(N);



void dfs(long long now, long long cnt){

    seen[now] = true;

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

        long long to = G[now][i];

        if(seen[to]) continue;

        dfs(to, cnt + Count[now]);

    }

    Count[now] += cnt;

    return;

}



int main(){

    cin.tie(nullptr);

    ios::sync_with_stdio(false);



    cin >> n >> q;

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

    }



    while(q--){

        long long p, x;

        cin >> p >> x;

        p--;

        Count[p] += x;

    }



    dfs(0, 0);



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

        cout << Count[i] << ' ';

    }

    cout << endl;



    return 0;

}

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

using namespace std;



const int N = 200010;

vector<int> G[N];

vector<int> Count(N);

int n, q;



void dfs(int now, int pre){

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

        int to = G[now][i];

        if(to == pre) continue;

        Count[to] += Count[now];

        dfs(to, now);

    }

}



int main(){

    cin.tie(nullptr);

    ios::sync_with_stdio(false);



    cin >> n >> q;

    

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

    }



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

        int p, x;

        cin >> p >> x;

        p--;

        Count[p] += x;

    }



    dfs(0, -1);



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

        cout << Count[i] << ' ';

    }

    cout << endl;



    return 0;

}

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

using namespace std;



long long n, q;



const long long N = 200010;

vector<long long> G[N];

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

vector<bool> seen(N);



void dfs(long long now, long long cnt){

    seen[now] = true;

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

        long long to = G[now][i];

        if(seen[to]) continue;

        dfs(to, cnt + Count[now]);

    }

    Count[now] += cnt;

    return;

}



int main(){

    cin.tie(nullptr);

    ios::sync_with_stdio(false);



    cin >> n >> q;

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

    }



    while(q--){

        long long p, x;

        cin >> p >> x;

        p--;

        Count[p] += x;

    }



    dfs(0, 0);



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

        cout << Count[i] << ' ';

    }

    cout << endl;



    return 0;

}


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

using namespace std;



const int N = 200010;

vector<int> G[N];

vector<int> Count(N);

int n, q;



void dfs(int now, int pre){

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

        int to = G[now][i];

        if(to == pre) continue;

        Count[to] += Count[now];

        dfs(to, now);

    }

}



int main(){

    cin.tie(nullptr);

    ios::sync_with_stdio(false);



    cin >> n >> q;

    

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

    }



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

        int p, x;

        cin >> p >> x;

        p--;

        Count[p] += x;

    }



    dfs(0, -1);



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

        cout << Count[i] << ' ';

    }

    cout << endl;



    return 0;

}

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

#include <algorithm>

#include <stdio.h>

#include <string>

#include <string.h>

#include <map>

#include <math.h>

#include <vector>

#include <set>

#include <queue>

#include <map>

#include <deque>

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

using namespace std;

typedef long long ll;

const int N=1e5+50;

const int inf=0x3f3f3f3f;

int n,k;

vector<bool> vis(200001,0);

vector<ll> a(200001,0);

vector<int> g[200001];

void dfs(int t,ll val)

{

    vis[t]=1;

    a[t]+=val;

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

    {

        int v=g[t][i];

        if(!vis[v])

        {

            dfs(v,a[t]);

        }

    }

}

int main()

{

    //freopen("/Users/zilongzhang/Desktop//l.txt","r",stdin);

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

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

            int x, y;

            scanf("%d %d", &x, &y);

            x--;

            y--;

            g[x].push_back(y);

            g[y].push_back(x);

        }

        while(k--)

        {

            int l,b;

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

            l--;

            a[l]+=b;

        }

        dfs(0,0);

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

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

    return 0;

}


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

#include <algorithm>

#include <stdio.h>

#include <string>

#include <string.h>

#include <map>

#include <math.h>

#include <vector>

#include <set>

#include <queue>

#include <map>

#include <deque>

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

using namespace std;

typedef long long ll;

const int N=1e5+50;

const int inf=0x3f3f3f3f;

int n,k;

ll a[200050];

bool vis[200050];

vector<int >g[200050];

void dfs(int t,ll val)

{

    vis[t]=1;

    a[t]+=val;

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

    {

        int v=g[t][i];

        if(!vis[v])

        {

            dfs(v,a[t]);

        }

    }

}

int main()

{

    //freopen("/Users/zilongzhang/Desktop//l.txt","r",stdin);

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

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

            int x, y;

            scanf("%d %d", &x, &y);

            x--;

            y--;

            g[x].push_back(y);

            g[y].push_back(x);

        }

        while(k--)

        {

            int l,b;

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

            l--;

            a[l]+=b;

        }

        dfs(0,0);

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

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

    return 0;

}


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

#include <vector>

#include <algorithm>



using namespace std;



typedef long long ll;

typedef pair<int, int> P;



int cnt[200001];

vector<int> tree[200001];



void dfs(int v, int sum){

    if(tree[v].size() == 0)     return;

    

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

        int nv = tree[v][i];

        cnt[nv] += sum;

        dfs(nv, cnt[nv]);

    }

}



int main(){

    int n, q;

    cin >> n >> q;

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

        int a, b;

        cin >> a >> b;

        --a;

        --b;

        tree[a].push_back(b);

    }

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

        int x, y;

        cin >> x >> y;

        --x;

        cnt[x] += y;

    }



    dfs(0, cnt[0]);

    

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

        cout << cnt[i] << (i==n-1 ? "\n" : " ");

    }

}

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

#include <vector>

#include <algorithm>

#include <cmath>

#include <queue>

#include <string>

#include <map>

#include <set>

#include <stack>

#include <tuple>

#include <deque>

#include <numeric>

#include <bitset>

#include <iomanip>

#include <cassert>

#include <chrono>

#include <random>

#include <limits>

#include <iterator>

#include <functional>

#include <sstream>

#include <complex>

using namespace std;



typedef long long ll;

typedef uint64_t ull;

typedef pair<int, int> P;

constexpr double EPS = 1e-9;

constexpr int INF = 1001001001;

constexpr int mod = 1000000007;

// constexpr int mod = 998244353;



#define chmax(x, y) x = max(x, y)

#define chmin(x, y) x = min(x, y)



int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    int n, q;

    cin >> n >> q;

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

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

        int a, b;

        cin >> a >> b;

        --a, --b;

        graph[a].emplace_back(b);

        graph[b].emplace_back(a);

    }

    vector<int> score(n, 0);

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

        int p, x;

        cin >> p >> x;

        --p;

        score[p] += x;

    }



    auto dfs = [&](auto&& self, int from = 0, int sum = 0, int p = -1) -> void {

        score[from] += sum;

        sum = score[from];

        for(int to : graph[from]){

            if(to == p) continue;

            self(self, to, sum, from);

        }

    };



    dfs(dfs);

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

        cout << score[i];

        cout << ((i == n - 1) ? '\n' : ' ');

    }

}

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

using namespace std;



vector<int> graph[200005];

int cost[200005];



void dfs(int from = 0, int p = -1, int sum = 0){

    sum += cost[from];

    for(int to : graph[from]){

        if(to == p) continue;

        dfs(to, from, sum);

    }

    sum -= cost[from];

    cost[from] += sum;

    return;

}



int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    

    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;

        cost[p] += x;

    }

    dfs();

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

        cout << cost[i];

        cout << ((i == n - 1) ? "\n" : " ");

    }

}

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

#include <vector>

#include <algorithm>

#include <cmath>

#include <queue>

#include <string>

#include <map>

#include <set>

#include <stack>

#include <tuple>

#include <deque>

#include <numeric>

#include <bitset>

#include <iomanip>

#include <cassert>

#include <chrono>

#include <random>

#include <limits>

#include <iterator>

#include <functional>

#include <sstream>

#include <complex>

using namespace std;



typedef long long ll;

typedef uint64_t ull;

typedef pair<int, int> P;

constexpr double EPS = 1e-9;

constexpr int INF = 1001001001;

constexpr int mod = 1000000007;

// constexpr int mod = 998244353;



#define chmax(x, y) x = max(x, y)

#define chmin(x, y) x = min(x, y)



int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);



    int n, q;

    cin >> n >> q;

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

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

        int a, b;

        cin >> a >> b;

        --a, --b;

        graph[a].emplace_back(b);

        graph[b].emplace_back(a);

    }

    vector<int> score(n, 0);

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

        int p, x;

        cin >> p >> x;

        --p;

        score[p] += x;

    }



    auto dfs = [&](auto&& self, int from = 0, int sum = 0, int p = -1) -> void {

        score[from] += sum;

        sum = score[from];

        for(int to : graph[from]){

            if(to == p) continue;

            self(self, to, sum, from);

        }

    };



    dfs(dfs);

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

        cout << score[i];

        cout << ((i == n - 1) ? '\n' : ' ');

    }

}

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

using namespace std;

typedef long long ll;

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

#define vi vector<int>

#define vs vector<string>

#define vll vector<ll>



vi to[202000];

vi 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) {

        cout << ((i > 0) ? " " : "") << ans[i];

    }

    

    cout << endl;

    return 0;

}

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

using namespace std;

typedef long long ll;

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

#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)

#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)

#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)

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

#define rall(x) (x).rbegin(), (x).rend()

#define sz(x) ((ll)(x).size())

#define len(x) ((ll)(x).length())

#define endl "\n"



ll n, q;

vector<vector<ll>> g;

vector<ll> dp;



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

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

    for(auto &u : g[v]) {

        if (u == p) continue;

        dfs(u, v);

    }

}



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);

    // ifstream in("input.txt");

    // cin.rdbuf(in.rdbuf());

    cin >> n >> q;

    g.resize(n);

    rep(i, n - 1) {

        ll a, b;

        cin >> a >> b;

        a--; b--;

        g[a].push_back(b);

        g[b].push_back(a);

    }

    dp.resize(n, 0);

    rep(i, q) {

        ll p, x;

        cin >> p >> x;

        p--;

        dp[p] += x;

    }

    dfs(0);

    rep(i, n) printf("%lld%s", dp[i], (i == (n - 1)) ? "\n" : " ");

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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;

}


// Optimized solution to the same problem (faster):
#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;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#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);

      }

  }

}

// Optimized solution to the same problem (faster):
#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);

}

// Fastest known solution for this problem: