input: Write a function to compare two binary trees and check if they are similar. Two trees are considered similar if they both have the same structure and the same values at each corresponding node. If both trees are None, they are considered similar. If only one of the trees is None, they are not similar. If the values at the root of both trees are different, they are not similar. Otherwise, recursively check the left and right subtrees for similarity.
  
  
  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
  # Create trees for testing
  root1 = TreeNode(1)
  root1.left = TreeNode(2)
  root1.right = TreeNode(3)
  
  root2 = TreeNode(1)
  root2.left = TreeNode(2)
  root2.right = TreeNode(3)
  
  root3 = TreeNode(1)
  root3.left = TreeNode(3)
  root3.right = TreeNode(2)
  
  root4 = TreeNode(1)
  root4.left = TreeNode(2)
  
  # Tests
  assert are_similar(root1, root2) == True
  assert are_similar(root1, root3) == False
  assert are_similar(root1, root4) == False
  assert are_similar(None, None) == True
  assert are_similar(root1, None) == 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)