dfs +  factorization
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 comp ;\n    map<int ,vector<int>>mp ;\n    int dfs(int node, int tar, int par, vector<int>& nums) {\n        // cout<<node<<endl;\n        int sum = nums[node];\n        for (auto it : mp[node]) {\n            if (it != par) {\n                sum += dfs(it, tar, node, nums);\n            }\n        }\n        if (sum == tar) {\n            comp--;  \n            return 0;  \n        }\n        return sum;\n    }\n\n    int componentValue(vector<int>& nums, vector<vector<int>>& edges) {\n        int  sum = 0 ;\n        for(int i :  nums) sum += i ;\n        int  t =  sqrt(sum) ;\n        int op = 0 ;\n    \n        for (auto& it : edges) {\n            \n            mp[it[0]].push_back(it[1]);\n            mp[it[1]].push_back(it[0]);\n        }\n\n        for (int i = 1 ;  i <=  t ;  i++){\n            if(sum%i == 0){\n                int a =  sum/i ;\n                int b =  i ;\n                comp = sum/a ;\n                // cout<<a<<endl;\n                \n                int ans =   dfs(0 , a   , -1 ,  nums ) ;\n                // cout<<comp<<endl;\n                if(comp == 0){\n                    op =  max(op ,  (sum/a) - 1 ) ;\n                }\n                comp =  sum/b ;\n                ans =  dfs(0 ,  b ,  - 1 ,  nums) ;\n                if(comp ==  0 ){\n                    op =  max(op ,  (sum/b) - 1) ;\n                }\n                // cout<<a<<" "<<b<<endl;\n            }\n        }\n        return  op ;\n    }\n};\n```
['C++']