human
Solve in Python:
Given a binary tree, we install cameras on the nodes of the tree. 
Each camera at a node can monitor its parent, itself, and its immediate children.
Calculate the minimum number of cameras needed to monitor all nodes of the tree.
 
Example 1:

Input: [0,0,null,0,0]
Output: 1
Explanation: One camera is enough to monitor all nodes if placed as shown.

Example 2:

Input: [0,0,null,0,null,0,null,null,0]
Output: 2
Explanation: At least two cameras are needed to monitor all nodes of the tree. The above image shows one of the valid configurations of camera placement.

Note:

The number of nodes in the given tree will be in the range [1, 1000].
Every node has value 0.
assistant
#Here is Python code to calculate the minimum number of cameras needed to monitor all nodes of the tree.

# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def minCameraCover(self, root: TreeNode) -> int:
        
        
        def dfs(node):
            nonlocal cnt
            
            if node:
                left = dfs(node.left)
                right = dfs(node.right)
                
                if not left or not right:
                    cnt += 1
                    return 2
                elif left == 2 or right == 2:
                    return 1
                else:
                    return 0
            else:
                return 1
        
        cnt = 0
        
        if not dfs(root):
            return cnt + 1
        else:
            return cnt