C++ || Easy understanding || explained
\nclass Solution {\npublic:\n    \n    //to count\n    int countIt(vector<int> arr, int x,int &sum){\n        int count=0;\n        for(auto &itr:arr){\n       
```\nclass Solution {\npublic:\n    \n    //to count\n    int countIt(vector<int> arr, int x,int &sum){\n        int count=0;\n        for(auto &itr:arr){\n            if(itr==x) count++;\n            sum+=itr;\n        }\n        return count;\n    }\n    \n\n    //dfs traversal\n    int dfs(vector<int> &nums, int cur, vector<int> adj[], int prev, int target){\n        \n        int curSum=nums[cur];\n        \n        for(auto &itr : adj[cur]){\n            if(itr==prev) continue;     // avoid going backside in graph else infi loop\n            curSum+=dfs(nums,itr,adj,cur,target);\n        }\n        \n        //on returning back in recursion if you get target break \n        //it there and start sum from 0 for next\n        \n        if(curSum==target) return 0;\n        else return curSum;\n    }\n    \n    //main() start\n    int componentValue(vector<int>& nums, vector<vector<int>>& edges) {\n        vector<int> adj[nums.size()];\n        \n        //make graph\n        for(auto &itr:edges){\n            adj[itr[0]].push_back(itr[1]);\n            adj[itr[1]].push_back(itr[0]);\n        }\n        \n        //if all are of same nums[i] divide each node as individual also get total sum\n        int sum=0;\n        if(countIt(nums,nums[0],sum)==nums.size()) return nums.size()-1;\n        \n        //check for what it is dividable\n        for(int i=nums.size()-1;i>=2;i--){\n            if(sum%i != 0) continue;            // not dividable in i parts\n            int res=dfs(nums,0,adj,-1, sum/i);    //array , start , graph , parent, target\n            if(res==0) return i-1;  // edges removed = total components divided into -1 \n        }\n        \n        \n        return 0;\n    }\n};\n```
['Depth-First Search', 'C']