✅ C++ Simple + Clean | Simple modified DFS | Heavily Commented 100%  | Beginner Friendly
\nclass Solution {\npublic:\n    \n    // dfs traversal of graph\n    int dfs(vector<int>&nums, vector<vector<int>>&g, int cur, int parent, int target)\n    {\n
```\nclass Solution {\npublic:\n    \n    // dfs traversal of graph\n    int dfs(vector<int>&nums, vector<vector<int>>&g, int cur, int parent, int target)\n    {\n        int curSum = nums[cur];\n        for(auto &nbr : g[cur])\n        {\n            if(nbr == parent) continue;     // avoid going backside in graph else infinite loop\n            curSum += dfs(nums, g, nbr, 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) \n            return 0;\n        else \n            return curSum;\n    }\n    \n\t\n    int componentValue(vector<int>& nums, vector<vector<int>>& edges) \n    {\n        int n = nums.size();\n        vector<vector<int>>g(n);\n        \n        // make graph\n        for(auto e : edges){\n            g[e[0]].push_back(e[1]);\n            g[e[1]].push_back(e[0]);\n        }\n        \n        int sum = accumulate(nums.begin(), nums.end(), 0);\n        \n        // Handle early this Edge case will save time \n        // if all values of nums are same divide each node as individual also \n        // get total sum, i.e all nodes have same value.\n        \n        unordered_set<int>st(nums.begin(), nums.end());\n        if(st.size() == 1) return n-1;\n        \n        // start from maximum (i.e n-1) number of components to minimum no. of components that is "2"\n        for(int i=n-1;i>=2;i--)\n        {\n            if(sum%i != 0) continue;               // not dividable into "i" components\n            \n            int ans = dfs(nums, g, 0, -1, sum/i);  // value array , graph , start , parent , EachComponentSum\n            \n            // if ans finally returned to "0" means all components are successfully divided into sum of "sum/i"\n            if(ans == 0) return i-1;               // edges removed = total components divided into - 1 \n        }\n        return 0;\n    }\n};\n```\n\n----\n***Thanks for Upvoting !***\n\uD83D\uDE42
['Depth-First Search', 'Graph', 'C', 'C++']