C++ easy DFS
Approach\n Describe your approach to solving the problem. \n1. traverse the tree from root by DFS.\n2. if a subtree we visited can form a conponent with total s
# Approach\n<!-- Describe your approach to solving the problem. -->\n1. traverse the tree from root by DFS.\n2. if a subtree we visited can form a conponent with total sum target, than we can delete it from the tree.\n3. the function "tarverse" return the sum of value of subtree minus the sum of value of the subtees we deleted.\n4. if the tree can be splited into i part, than the function traverse will return 0. Because the tree is splited completely.\n\n# time complexity: O(log(sum(nums)*n)\n# Code\n```\nclass Solution {\npublic:\n    int componentValue(vector<int>& nums, vector<vector<int>>& edges) {\n        int sum=0, n=nums.size();\n        \n        // sum of value\n        for (int i=0; i<n; ++i)\n            sum+=nums[i];\n        \n        vector<vector<int>> next(n);\n        \n        // create edges map\n        for (auto e : edges) {\n            next[e[0]].push_back(e[1]);\n            next[e[1]].push_back(e[0]);\n        }\n        \n        for (int i=n; i>1; --i) {\n            if (sum%i) continue;  // there is no probability that split the tree into i part.\n            vector<int> temp(n);\n            if (traverse(nums, next, 0, temp, sum/i)==0) return i-1;\n        }\n        return 0;\n    }\n    \n    int traverse(vector<int>& nums, vector<vector<int>>& next, int cur, vector<int>& temp, int target) {\n        temp[cur]=nums[cur];\n        for (auto n : next[cur]) {\n            if (temp[n]) continue; // this condition represents that the node n has been visited.\n            temp[cur]+=traverse(nums, next, n, temp, target);\n            // If temp[cur]>target means that we fail the separation.\n            // In this condition, we just return a very large integer.\n            if (temp[cur]>target) return 1e7;\n        }\n        // this condition represents that the substree rooted at cur can be deleted from the tree. So, the sum of value can not add up to the parent of curent node.\n        if (temp[cur]==target) return 0;\n        return temp[cur];\n    }\n};\n```
['Depth-First Search', 'C++']