Explanation which you are searching for!!
\nclass Solution:\n    def averageOfSubtree(self, root: Optional[TreeNode]) -> int:\n        self.cnt=0\n        def dfs(node):\n            if not node:return 
```\nclass Solution:\n    def averageOfSubtree(self, root: Optional[TreeNode]) -> int:\n        self.cnt=0\n        def dfs(node):\n            if not node:return [0,0]\n            \n            x,cntx=dfs(node.left)\n            y,cnty=dfs(node.right)\n            if node.val==(x+y+node.val)//(cntx+cnty+1):\n                self.cnt+=1\n            return [node.val+x+y,cntx+cnty+1]\n            \n        dfs(root)\n        return self.cnt\n```
[]