Easy Dfs Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int cnt_ans;\n    int dfs(int ver, int par, int cnt, vector<vector<int>>& g, vector<int>& nums){\n\n        int sum = nums[ver];\n        for(auto child: g[ver]){\n            if(child == par) continue;\n            int child_sum = dfs(child, ver, cnt, g, nums);\n            if(child_sum > cnt) return 1e6;\n            if(child_sum == cnt){\n                cnt_ans++;\n            }\n            else sum += child_sum;\n        }\n        if(sum > cnt) return 1e6;\n        return sum;\n    }\n    int componentValue(vector<int>& nums, vector<vector<int>>& edges) {\n        int n = nums.size();\n        vector<vector<int> > g(n);\n        for(auto it: edges){\n            g[it[0]].push_back(it[1]);\n            g[it[1]].push_back(it[0]);\n        }\n\n        int sum = 0;\n        for(auto it: nums) sum += it;\n\n        vector<int> facs;\n        for(int i = 1; i <= sum; i++){\n            if(sum % i == 0) facs.push_back(i);\n        }\n\n\n        int ans = 0;\n        for(auto it: facs){\n            cnt_ans = 0;\n            if(dfs(0, -1, it, g, nums) != it) continue;\n            ans = max(ans, cnt_ans);\n        }\n\n        return ans;\n    }\n};\n```
['Tree', 'Depth-First Search', 'C++']