```
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def rob(self, root):
if root is None:
return 0
return max(self.robInclude(root), self.robExclude(root))
def robInclude(self, node):
if node is None:
return 0
return self.robExclude(node.left) + self.robExclude(node.right) + node.val
def robExclude(self, node):
if node is None:
return 0
return self.rob(node.left) + self.rob(node.right)
```