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

}


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

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

}


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

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

}


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

int a[200050];

bool vis[200050];

vector<int >g[200050];

void dfs(int t,int 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("%d ",a[i]);

    return 0;

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

}


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

int a[200050];

bool vis[200050];

vector<int >g[200050];

void bfs()

{

    queue<int>q;

    q.push(1);

    while(q.size())

    {

        int x=q.front();

        q.pop();

        vis[x]=1;

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

        {

            int v=g[x][i];

            if(!vis[v])

            {

                a[v]+=a[x];

                q.push(v);

            }

        }

    }

}

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

            g[x].push_back(y);

            g[y].push_back(x);

        }

        while(k--)

        {

            int l,b;

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

            a[l]+=b;

        }

        bfs();

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

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

    return 0;

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

    }

}

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

    }

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

    }

}

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

    }

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

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

}

// Faster C++ solution for the same problem (measured speedup: 6.436393352487461x):
#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 sz(x) ((ll)(x).size())

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



ll n, q;

vector<vector<ll>> g;

vector<ll> cnt;



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

    for(auto u : g[v]) {

        if (u == p) continue;

        cnt[u] += cnt[v];

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

    cnt.resize(n, 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 p, x;

        cin >> p >> x;

        p--;

        cnt[p] += x;

    }

    dfs(0);

    rep(i, n) printf("%lld%s", cnt[i], (i == (n - 1)) ? "\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++)

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

}

// Faster C++ solution for the same problem (measured speedup: 6.436404167099279x):
#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 sz(x) ((ll)(x).size())

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



ll n, q;

vector<vector<ll>> g;

vector<ll> ans;



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

    for(auto u : g[v]) {

        if (u == p) continue;

        ans[u] += ans[v];

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

    }

    ans.resize(n, 0);

    rep(i, q) {

        ll p, x;

        cin >> p >> x;

        p--;

        ans[p] += x;

    }

    dfs(0);

    rep(i, n) printf("%lld%s", ans[i], (i == (n - 1)) ? "\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++)

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

}

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



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);

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

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

    ll n, q;

    cin >> n >> q;

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

    rep(i, n - 1) {

        ll a, b;

        cin >> a >> b;

        a--; b--;

        g[a].push_back(b);

        g[b].push_back(a);

    }

    vector<ll> dp(n, 0);

    rep(i, q) {

        ll p, x;

        cin >> p >> x;

        p--;

        dp[p] += x;

    }

    vector<bool> seen(n, false);

    queue<ll> que;

    que.push(0);

    while(!que.empty()) {

        ll v = que.front(); que.pop();

        seen[v] = true;

        for(auto u : g[v]) {

            if (u == v) continue;

            if (seen[u]) continue;

            dp[u] += dp[v];

            que.push(u);

        }

    }

    rep(i, n) printf("%lld%s", dp[i], (i == (n - 1)) ? "\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++)

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

}

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

}