Simple Logic, DFS+ Factors,C++
\nclass Solution {\npublic:\n    vector<vector<int>> adj;\n    int comp;\n    int dfs(vector<int>& nums,int v, int parent,int val) {\n        int total = nums[v
```\nclass Solution {\npublic:\n    vector<vector<int>> adj;\n    int comp;\n    int dfs(vector<int>& nums,int v, int parent,int val) {\n        int total = nums[v];\n        for(auto x: adj[v]) {\n            if(x == parent) continue;\n            total += dfs(nums,x, v,val);\n        } \n        if(total == val) {\n            comp--;\n            return 0;\n        }\n        return total;\n    }\n    int componentValue(vector<int>& nums, vector<vector<int>>& edges) {\n        int n = nums.size();\n        adj.resize(n);\n        for(auto e: edges) {\n            adj[e[0]].push_back(e[1]);\n            adj[e[1]].push_back(e[0]);\n        }\n        \n        if(count(nums.begin(), nums.end(), nums[0]) == n) return n - 1;\n        int sum = accumulate(nums.begin(), nums.end(), 0);\n        int res = 0;\n    \n        for(int i = 2; i * i <= sum; ++i) {\n            if(sum % i == 0) {\n                comp = i;\n                dfs(nums,0, -1,sum / i);\n                if(comp == 0) res = max(res, i - 1);\n                \n                comp = sum / i;\n                dfs(nums,0, -1,i);\n                if(comp == 0) res = max(res, (sum / i) - 1);\n            }\n        }\n        \n        return res;\n    }\n};\n```
['C']