input: Write a function to compare two binary trees to check if they are similar. Two binary trees are considered similar if they have the same structure and the same node values at each corresponding position in the tree. The function should return True if the two trees are similar, and False otherwise. If either of the trees is empty (i.e., the root is None), the function should return True only if both trees are empty.
  
  
  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 and root2) is None or (root1 or root2) is None:
          return False
      if root1.val != root2.val:
          return False
      else:
          return are_similar(root1.left, root2.left) and are_similar(root1.right, root2.right)
  
  # Test cases
  # Tree 1:   1
  #         /   \
  #        2     3
  # Tree 2:   1
  #         /   \
  #        2     3
  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
  
  # Tree 3:   1
  #         /   \
  #        2     4
  # Tree 4:   1
  #         /   \
  #        2     3
  root3 = TreeNode(1)
  root3.left = TreeNode(2)
  root3.right = TreeNode(4)
  
  root4 = TreeNode(1)
  root4.left = TreeNode(2)
  root4.right = TreeNode(3)
  
  assert are_similar(root3, root4) == False
  
  # Tree 5:   1
  #         /   \
  #        2     3
  # Tree 6: None
  root5 = TreeNode(1)
  root5.left = TreeNode(2)
  root5.right = TreeNode(3)
  
  root6 = None
  
  assert are_similar(root5, root6) == False
  
  # Tree 7: None
  # Tree 8: None
  root7 = None
  root8 = None
  
  assert are_similar(root7, root8) == True
  
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)