C++ | DFS | Commented
\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0)
```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n    int total = 0;\n    TreeNode* found;\n    void find(TreeNode* root, int x) {\n        if(!root) return ;\n        ++total;\n        if(root->val == x) {\n            found = root;\n        }\n        find(root->left, x);\n        find(root->right, x);\n    }\n    int cnt = 0;\n    void dfs(TreeNode* root) {\n        if(!root) return;\n        cnt++;\n        dfs(root->left);\n        dfs(root->right);\n    }\n    bool btreeGameWinningMove(TreeNode* root, int n, int x) {\n        // We have three options to sucessfullly restrict the red color\n        // 1. We color the parent of the node x blue so that red expands \n        // only to its children.\n        // 2. We color the left child of the node x blue so that red\n        // expands only to its right children and it\'s ancestor.\n        // 3. We color the right child of the node x blue so that red \n        // expands only to it\'s left and it\'s ancestor\n        // Among these three options if in any case we get more blues than reds\n        // Our answer will be true;\n        \n        // 1.\n        find(root, x);\n        TreeNode* nr = found;\n        dfs(nr);\n        int red = cnt;\n        int blue = total - cnt;\n        cnt = 0;\n        if(blue > red) return true;\n        // 2.\n        dfs(nr->left);\n        blue = cnt;\n        red = total - cnt;\n        cnt = 0;\n        if(blue > red) return true;\n        // 3.\n        dfs(nr->right);\n        blue = cnt;\n        red = total - blue;\n        if(blue > red) return true;\n        return false;\n    }\n};\n```
['Binary Tree']