c++ | easy | fast
\n\n# Code\n\nclass Solution {\npublic:\n    vector<int> arr;\n    vector<vector<int>> g;\n    \n    int dfs(int ind,int parent,const int target)\n    {\n      
\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> arr;\n    vector<vector<int>> g;\n    \n    int dfs(int ind,int parent,const int target)\n    {\n        int val = arr[ind];\n        \n        for(auto it : g[ind]){\n            if(it == parent) continue;\n            val += dfs(it,ind,target);\n        }\n        \n        if(val == target) return 0;\n        return val;\n    }\n    int componentValue(vector<int>& nums, vector<vector<int>>& edges) {\n        g.clear(),arr.clear();\n        int n = nums.size();\n        g.resize(n),arr.resize(n);\n        int sum = 0;\n        \n        for(auto i: edges){\n            g[i[0]].push_back(i[1]);\n            g[i[1]].push_back(i[0]);\n        }\n        \n        for(int j=0;j<n;j++){\n            sum += nums[j];\n            arr[j] = nums[j];\n        }\n        \n        int result = 0;\n        for(int parts = 1;parts <= n;parts++){\n            if(sum%parts != 0) continue;\n            if(dfs(0,-1,sum/parts) !=0) continue;\n            \n            result = max(result,parts-1);\n        }\n        return result;\n    }\n};\n```
['C++']