#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=2e5+10;
vector<int>e[maxn];
int n,m;
int val[maxn],a[maxn];
void dfs(int u,int ff)
{
a[u]=a[ff]+val[u];
for(auto v:e[u])
{
if(v==ff)continue;
dfs(v,u);
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n-1;i++)
{
int x,y;
cin>>x>>y;
e[x].push_back(y);
e[y].push_back(x);
}
while(m--)
{
int pos,x;
cin>>pos>>x;
val[pos]+=x;
}
dfs(1,0);
for(int i=1;i<=n;i++)
{
cout<<a[i]<<" ";
}
return 0;
} 1
这是 2025年10月22日 存档的第 1 版,不是当前版本。查看当前版本