C++ code using DFS
Code\n\nclass Solution {\npublic:\n    pair<int, int>solve(vector<int>adj[], int par, int node, vector<int>&nums, int value){\n        pair<int, int>res;\n\n   
# Code\n```\nclass Solution {\npublic:\n    pair<int, int>solve(vector<int>adj[], int par, int node, vector<int>&nums, int value){\n        pair<int, int>res;\n\n        int val1 = nums[node], val2 = 0;\n\n        for(auto it: adj[node]){\n            if(it == par)\n                continue;\n            auto temp = solve(adj, node, it, nums, value);\n\n            if(temp.first == -1){\n                return {-1, -1};\n            }\n\n            val1+=temp.first;\n            val2+=temp.second;\n        }\n\n        if(val1 > value){\n            return {-1, -1};\n        }\n\n        if(val1 == value){\n            return {0, val2+1};\n        }\n\n        return {val1, val2};\n    }\n\n    bool isPossible(vector<int>adj[], int root, vector<int>&nums, int countComp, int value){\n        auto temp = solve(adj, -1, 0, nums, value);\n        if(temp.second == countComp && temp.first == 0)\n            return true;\n        \n        return false;\n    }\n\n    int componentValue(vector<int>& nums, vector<vector<int>>& edges) {\n        int sum = 0, maxi = 0;\n        for(int i=0;i<nums.size();i++){\n            maxi = max(maxi, nums[i]);\n            sum+=nums[i];\n        }\n\n        vector<int>values;\n        for(int i=sum/maxi;i>=1;i--){\n            if(sum%i == 0)\n                values.push_back(i);\n        }\n\n        int n = nums.size();\n        vector<int>adj[n];\n\n        for(auto it: edges){\n            adj[it[0]].push_back(it[1]);\n            adj[it[1]].push_back(it[0]);\n        }\n\n        for(int i=0;i<values.size();i++){\n            if(isPossible(adj, 0, nums, values[i], sum/values[i]))\n                return values[i] - 1;\n        }\n\n        return 0;\n    }\n};\n```
['Depth-First Search', 'Graph', 'C++']