Language: C++


void dfs(int p, int v) {
	for (auto u: ad[v]) 
		if (u != p) {
			kid[v].push_back(u);
			par[u] = v;
			dfs(v, u);
		}
}

int solve(int v) {
	for (auto u: kid[v])
		solve(u);
	int z = 0;
	bool ok = 0;
	if (!kid[v].size())
		ok = 1;
	for (auto u: kid[v]) {
		if (!res[u]) {
			z++;
			if (!haz[u])
				ok = 1;
		}
		res[v] += res[u];
	}
	if (z) 
		haz[v] = 1;
	res[v] += max(z - 1, 0);
	return ok;
}

int main() {
	cin >> n;
	for (int i = 1; i < n; i++) {
		int x, y;
		cin >> x >> y;
		x++, y++;
		ad[x].push_back(y);
		ad[y].push_back(x);
	}
	dfs(0, 1);
	int t = solve(1);
	cout << max(1 - t + res[1], 1) << endl;
	return 0;
}

Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:3:22: error: 'ad' was not declared in this scope
    3 |         for (auto u: ad[v])
      |                      ^~
a.cc:5:25: error: 'kid' was not declared in this scope
    5 |                         kid[v].push_back(u);
      |                         ^~~
a.cc:6:25: error: 'par' was not declared in this scope
    6 |                         par[u] = v;
      |                         ^~~
a.cc: In function 'int solve(int)':
a.cc:12:22: error: 'kid' was not declared in this scope
   12 |         for (auto u: kid[v])
      |                      ^~~
a.cc:16:14: error: 'kid' was not declared in this scope
   16 |         if (!kid[v].size())
      |              ^~~
a.cc:18:22: error: 'kid' was not declared in this scope
   18 |         for (auto u: kid[v]) {
      |                      ^~~
a.cc:19:22: error: 'res' was not declared in this scope
   19 |                 if (!res[u]) {
      |                      ^~~
a.cc:21:30: error: 'haz' was not declared in this scope
   21 |                         if (!haz[u])
      |                              ^~~
a.cc:24:17: error: 'res' was not declared in this scope
   24 |                 res[v] += res[u];
      |                 ^~~
a.cc:27:17: error: 'haz' was not declared in this scope
   27 |                 haz[v] = 1;
      |                 ^~~
a.cc:28:9: error: 'res' was not declared in this scope
   28 |         res[v] += max(z - 1, 0);
      |         ^~~
a.cc:28:19: error: 'max' was not declared in this scope
   28 |         res[v] += max(z - 1, 0);
      |                   ^~~
a.cc: In function 'int main()':
a.cc:33:9: error: 'cin' was not declared in this scope
   33 |         cin >> n;
      |         ^~~
a.cc:33:16: error: 'n' was not declared in this scope
   33 |         cin >> n;
      |                ^
a.cc:38:17: error: 'ad' was not declared in this scope
   38 |                 ad[x].push_back(y);
      |                 ^~
a.cc:43:9: error: 'cout' was not declared in this scope
   43 |         cout << max(1 - t + res[1], 1) << endl;
      |         ^~~~
a.cc:43:29: error: 'res' was not declared in this scope
   43 |         cout << max(1 - t + res[1], 1) << endl;
      |                             ^~~
a.cc:43:17: error: 'max' was not declared in this scope
   43 |         cout << max(1 - t + res[1], 1) << endl;
      |                 ^~~
a.cc:43:43: error: 'endl' was not declared in this scope
   43 |         cout << max(1 - t + res[1], 1) << endl;
      |                                           ^~~~