#include <bits/stdc++.h>
using
namespace
std;
struct
Node {
int
data;
Node* left;
Node* right;
Node(
int
val)
{
data = val;
left = right = NULL;
}
};
int
solve(
int
& ans, Node* root, Node* parent,
unordered_map<Node*,
int
>& dp)
{
if
(root == 0)
return
0;
int
cnt = solve(ans, root->left, root, dp);
cnt += solve(ans, root->right, root, dp);
if
(cnt == 0) {
if
(dp[root] == 0 && parent == 0) {
ans++;
return
1;
}
if
(dp[root] == 0)
return
1;
return
0;
}
else
{
if
(root->left != 0)
dp[root->left] = 1;
if
(root->right != 0)
dp[root->right] = 1;
dp[root] = 1;
if
(parent != 0)
dp[parent] = 1;
ans++;
return
0;
}
}
int
supplyVaccine(Node* root)
{
unordered_map<Node*,
int
> dp;
int
ans = 0;
solve(ans, root, 0, dp);
return
ans;
}
int
main()
{
string treeString;
Node* root =
new
Node(1);
root->left =
new
Node(2);
root->right =
new
Node(3);
root->right->right =
new
Node(4);
root->right->right->right =
new
Node(5);
root->right->right->right->right
=
new
Node(6);
cout << supplyVaccine(root) <<
"\n"
;
return
0;
}