Language: C++

#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
map<ll, ll>ins;
void facterize(ll n) {
	ll a = 2;
	while (n >= a * a) {
		if (n % a == 0) {
			ins[a]++;
			ins[a] = ins[a] % 1000000007;
			n /= a;
		}
		else {
			a++;
		}
	}
	ins[n]++;
}

vector<ll>relation[20], money(20, 1);
int dp[110][110];

int keta(int x) {
	int y = 0;
	while (x > 0) {
		y++;
		x /= 10;
	}
	return y;
}

int dy[] = { 0, 0, 1, -1,1,1,-1,-1 };
int dx[] = { 1, -1, 0, 0,1,-1,1,-1 };

void dfs(int x, int y) {
	land[x][y] = 0;
	for (int dx = -1;dx <= 1;++dx) {
		for (int dy = -1;dy <= dy;++dy) {
			int nx = x + dx, ny = y + dy;
			if (0 <= nx && nx < a && 0 <= ny && ny < b && land[nx][ny])dfs(nx, ny);
		}
	}
	return;
}
vector<int>to[10101010];

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) {
		cin >> a >> b;
		--a;
		--b;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	vector<int>ans(n);
	rep(i, q) {
		int p, x;
		cin >> p >> x;
		--p;
		ans[p] += x;
	}
	dfs(0);
	rep(i, n) {
		cout << ans[i] << endl;
	}
	return 0;
}


Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:75:9: error: 'land' was not declared in this scope; did you mean 'rand'?
   75 |         land[x][y] = 0;
      |         ^~~~
      |         rand
a.cc:79:45: error: 'a' was not declared in this scope
   79 |                         if (0 <= nx && nx < a && 0 <= ny && ny < b && land[nx][ny])dfs(nx, ny);
      |                                             ^
a.cc:79:66: error: 'b' was not declared in this scope
   79 |                         if (0 <= nx && nx < a && 0 <= ny && ny < b && land[nx][ny])dfs(nx, ny);
      |                                                                  ^
a.cc: At global scope:
a.cc:86:6: error: redefinition of 'void dfs(int, int)'
   86 | void dfs(int v, int p = -1) {
      |      ^~~
a.cc:74:6: note: 'void dfs(int, int)' previously defined here
   74 | void dfs(int x, int y) {
      |      ^~~
a.cc: In function 'void dfs(int, int)':
a.cc:89:17: error: 'ans' was not declared in this scope; did you mean 'ins'?
   89 |                 ans[u] += ans[v];
      |                 ^~~
      |                 ins
a.cc: In function 'int main()':
a.cc:98:24: error: 'a' was not declared in this scope
   98 |                 cin >> a >> b;
      |                        ^
a.cc:98:29: error: 'b' was not declared in this scope
   98 |                 cin >> a >> b;
      |                             ^
a.cc:111:12: error: too few arguments to function 'void dfs(int, int)'
  111 |         dfs(0);
      |         ~~~^~~
a.cc:74:6: note: declared here
   74 | void dfs(int x, int y) {
      |      ^~~