Easy C++ Solution using C++
\n# Approach\nThe solve function takes a TreeNode* representing the root of a binary tree and returns a pair of integers. The pair contains two values: the maxi
\n# Approach\nThe solve function takes a TreeNode* representing the root of a binary tree and returns a pair of integers. The pair contains two values: the maximum amount of money that can be robbed from the subtree rooted at root if root is included, and the maximum amount of money that can be robbed if root is not included.\n\nInside the solve function, the base case is checked first. If the root is NULL, indicating an empty subtree, a pair of zeros is returned.\n\nRecursively, the solve function is called for the left and right subtrees, and their results are stored in the left and right pairs.\n\nA new pair result is created to store the maximum amounts of money for the current subtree. The first value of result is calculated by adding the value of root->val (the money in the current house) to the sums of the second values from the left and right pairs (representing the maximum amounts when root is not included).\n\nThe second value of result is calculated by taking the maximum of the first and second values from the left pair and adding it to the maximum of the first and second values from the right pair.\n\nFinally, the maximum value between the first and second values of result is returned as the maximum amount of money that can be robbed.\n\nIn the rob function, the solve function is called for the root node, and the maximum of the first and second values from the returned pair is returned as the maximum amount of money that can be robbed from the entire binary tree.\n<!-- Describe your approach to solving the problem. -->\n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\npair<int,int >solve(TreeNode* root)\n{\n    if(root==NULL)\n        {\n           pair<int,int>p=make_pair(0,0);\n           return p;\n        }\n        pair<int,int>left=solve(root->left);\n        pair<int,int>right=solve(root->right);\n        pair<int,int > result;\n        result.first=root->val+left.second+right.second;\n        result.second=max(left.first,left.second)+max(right.first,right.second);\n        return {result.first,result.second};\n\n}\n    int rob(TreeNode* root)\n    {\n        pair<int,int>n=solve(root);\n        return max(n.first, n.second);\n    }\n};\n```
['Tree', 'Depth-First Search', 'Binary Tree', 'C++']