Simple CPP Solution | DFS Only
Code\n\nclass Solution {\npublic:\n    vector<vector<int>>g;\n    vector<int>arr;\n    \n    int dfs(int ind,int par,int target){\n        int val=arr[ind];\n  
# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>>g;\n    vector<int>arr;\n    \n    int dfs(int ind,int par,int target){\n        int val=arr[ind];\n        \n        for(auto it:g[ind]){\n            if(it == par) continue;\n            \n            val += dfs(it,ind,target);\n        }\n        if( val == target) return 0;\n        return val;\n        \n    }\n    \n    int componentValue(vector<int>& nums, vector<vector<int>>& ed) {\n        int n=nums.size();\n        if(n == 1) return 0;\n        \n        g.resize(n);\n        arr.resize(n);\n        \n        for(auto i:ed){\n            g[i[0]].push_back(i[1]);\n            g[i[1]].push_back(i[0]);\n            \n        }\n        \n        \n        int sum=0;\n        for(int i=0;i<n;i++){\n            sum += nums[i];\n            arr[i]= nums[i];\n        }\n        \n        \n       int res=0;\n        for(int part=1;part<=n;part++){\n            if(sum%part !=0 ) continue;\n            if(dfs(0,-1,sum/part) == 0){\n                res=max(res,part-1);\n            }\n        }\n        \n        return res;\n        \n        \n        \n        \n    }\n};\n```
['C++']