class Solution {

public:

int* dfs(TreeNode* root){

int row[2] = {0,0};

if(!root){

return row;

}

int* left = dfs(root->left);

int* right = dfs(root->right);

row[0] = left[1]+right[1];

row[1] = max(left[0]+right[0]+root->val, left[1]+right[1]);

return row;

}

int rob(TreeNode* root) {

return dfs(root)[1];

}

};