input: Write a function to compare two binary trees and check if they are similar. Two binary trees are considered similar if they have the same structure and the same values at corresponding nodes. If both roots are None, they are considered similar. If only one of the roots is None, they are not similar. If the values at the current nodes are different, they are not similar. Otherwise, recursively compare the left and right subtrees.
  class TreeNode:
      def __init__(self, x):
          self.val = x
          self.left = None
          self.right = None
  
  def are_similar(root1, root2):
      if root1 is None and root2 is None:
          return True
      if root1 is None or root2 is None:
          return False
      if root1.val != root2.val:
          return False
      return are_similar(root1.left, root2.left) and are_similar(root1.right, root2.right)
  
  # Test cases
  # Case 1: Both trees are empty
  assert are_similar(None, None) == True
  
  # Case 2: One tree is empty
  assert are_similar(None, TreeNode(1)) == False
  
  # Case 3: Both trees have the same structure and values
  root1 = TreeNode(1)
  root1.left = TreeNode(2)
  root1.right = TreeNode(3)
  
  root2 = TreeNode(1)
  root2.left = TreeNode(2)
  root2.right = TreeNode(3)
  
  assert are_similar(root1, root2) == True
  
  # Case 4: Trees have different structures
  root3 = TreeNode(1)
  root3.left = TreeNode(2)
  
  root4 = TreeNode(1)
  root4.right = TreeNode(2)
  
  assert are_similar(root3, root4) == False
  
  # Case 5: Trees have same structure but different values
  root5 = TreeNode(1)
  root5.left = TreeNode(2)
  root5.right = TreeNode(3)
  
  root6 = TreeNode(1)
  root6.left = TreeNode(4)
  root6.right = TreeNode(3)
  
  assert are_similar(root5, root6) == False
output: def are_similar(root1, root2):
      if root1 is None and root2 is None:
          return True
      if root1 is None or root2 is None:
          return False
      if root1.val != root2.val:
          return False
      return are_similar(root1.left, root2.left) and are_similar(root1.right, root2.right)