Two players play a turn based game on a binary tree. We are given the root of this binary tree, and the number of nodes n in the tree. n is odd, and each node has a distinct value from 1 to n.

Initially, the first player names a value x with 1 &lt;= x &lt;= n, and the second player names a value y with 1 &lt;= y &lt;= n and y != x. The first player colors the node with value x red, and the second player colors the node with value y blue.

Then, the players take turns starting with the first player. In each turn, that player chooses a node of their color (red if player 1, blue if player 2) and colors an uncolored neighbor of the chosen node (either the left child, right child, or parent of the chosen node.)

If (and only if) a player cannot choose such a node in this way, they must pass their turn. If both players pass their turn, the game ends, and the winner is the player that colored more nodes.

You are the second player. If it is possible to choose such a y to ensure you win the game, return true. If it is not possible, return false.

&nbsp;
Example 1:

Input: root = [1,2,3,4,5,6,7,8,9,10,11], n = 11, x = 3
Output: true
Explanation: The second player can choose the node with value 2.


Example 2:

Input: root = [1,2,3], n = 3, x = 1
Output: false


&nbsp;
Constraints:


	The number of nodes in the tree is n.
	1 &lt;= x &lt;= n &lt;= 100
	n is odd.
	1 &lt;= Node.val &lt;= n
	All the values of the tree are unique.


# 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 findParent(self,node,par = None):
        if node:
            self.parent[node.val] = par
            self.findParent(node.left,node)
            self.findParent(node.right,node)
    
    def traverse(self,node,done):
        if node:
            if node in done: return 0
            done[node] = True
            a = self.traverse(self.parent[node.val],done)
            b = self.traverse(node.left,done)
            c = self.traverse(node.right,done)
            return a + b + c + 1
        return 0
    
    def btreeGameWinningMove(self, root: Optional[TreeNode], n: int, x: int) -> bool:
        self.parent = {}
        self.findParent(root)
        parent = self.parent[x]
        node = root if root.val == x else parent.left if parent and parent.left and parent.left.val == x else parent.right
        up = self.traverse(parent,{node:True})
        left = self.traverse(node.left,{node:True})
        right = self.traverse(node.right,{node:True})
        return (up > left + right) or (left > up + right) or (right > up + left)
	class Solution {
	int xkaLeft=0,xkaRight=0;
	public int size(TreeNode node, int x)
	{
		if(node==null)
		{
			return 0;
		}
		int ls=size(node.left,x);
		int rs=size(node.right,x);

		if(node.val==x)
		{
			xkaLeft=ls;
			xkaRight=rs;
		}

		return ls+rs+1;
	}
	public boolean btreeGameWinningMove(TreeNode root, int n, int x) {

		size(root,x);
		int parent=n-(xkaLeft+xkaRight+1);
		int max=Math.max(parent,Math.max(xkaRight,xkaLeft));
		if(max>n/2)
		{
			return true;
		}
		return false;
	}
}
class Solution {
public:
    // nodex means "node with val = x" 
    // Idea behind this is to block either nodex's parent or it's left child or right child. Block means we will chose that node as nodey. Why? because it will devide the tree in two parts, one for player 1 and other for player 2. Then we have to just take the maximum no of nodes we can get, from these three nodes as head, and if max is greater than n/2, means we can will.
    TreeNode *nodex, *parentx;
    Solution(){
        nodex = NULL;
        parentx = NULL;
    }
    int count(TreeNode *root)
    {
        if (root == NULL)
            return 0;
        int a = count(root->left);
        int b = count(root->right);
        return a + b + 1;
    }
    bool findx(TreeNode *root, int x)
    {
        if (root == NULL)
            return false;
        parentx = root;
        if (root->val == x)
        {
            nodex = root;
            return true; 
        }
        bool a = findx(root->left, x);
        if (a)
            return true;
        bool b = findx(root->right, x);
        return b;
    }
    bool btreeGameWinningMove(TreeNode* root, int n, int x) {
        findx(root, x); // Find the node which has val = x
        int p = n - count(nodex); // Count the no of nodes of blue color, if we decide to take parent of nodex as nodey
        int r = count(nodex->right); // Count the no of nodes of blue color, if we decide to take right child of nodex as nodey
        int l = count(nodex->left); // Count the no of nodes of blue color, if we decide to take left child of nodex as nodey
        int mx = max(p,r);
        mx = max(mx, l); // max of all three possible scenarios
        if (mx > n/2)
            return true;
        else
            return false;
    }
};
var left, right, val;
var btreeGameWinningMove = function(root, n, x) {
    function count(node) {
        if (node == null)
            return 0;
        var l = count(node.left);
        var r = count(node.right);
        if (node.val == val) {
            left = l;
            right = r;
        }
        return l + r + 1;
    }
    val = x;
    count(root);
    return Math.max(n - left - right - 1, Math.max(left, right)) > n / 2;
};
Binary Tree Coloring Game