text: from typing import Optional
  
  
  # 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
  
  def btreeGameWinningMove(self, root: Optional[TreeNode], n: int, x: int) -> bool:
  
      self.parent, self.left, self.rigth = None, None, None
  
      def find_first(cur_node: Optional[TreeNode], parent: Optional[TreeNode]):
          if not cur_node:
              return
  
          if cur_node.val == x:
              self.left = cur_node.left
              self.right = cur_node.right
              self.parent = parent
              return
  
          find_first(cur_node.left, TreeNode(cur_node.val, parent, cur_node.right))
          find_first(cur_node.right, TreeNode(cur_node.val, cur_node.left, parent))
  
      def dfs(cur_node: Optional[TreeNode]) -> int:
          if not cur_node:
              return 0
  
          return dfs(cur_node.left) + dfs(cur_node.right) + 1
  
      find_first(root, None)
  
      left = dfs(self.left)
      right = dfs(self.right)
      parent = dfs(self.parent)
  
      if left > right + parent + 1 or right > left + parent + 1 or parent > left + right + 1:
          return True
      return False