# Definition for a binary tree node.
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

class Solution:
    def pruneTree(self, root):
        """
        :type root: TreeNode
        :rtype: TreeNode
        """
        def iscontainone(root):
            if not root:
                return False
            if root.val==1:
                return True
            else:
                return iscontainone(root.left) or iscontainone(root.right)
        def prune(root):
            if not root:
                return
            if not iscontainone(root.left):
                root.left=None
            else:
                prune(root.left)
            if not iscontainone(root.right):
                root.right=None
            else:
                prune(root.right)
        if not root:
            return None
        if root.val==0 and not iscontainone(root.left) and not iscontainone(root.right):
            return None
        else:
            prune(root)
        return root
s=Solution()
root=TreeNode(1)
root.right=TreeNode(0)
root.right.left=TreeNode(0)
root.right.right=TreeNode(1)
print(s.pruneTree(root))