Easy C++ Solution
\n# Code\n\nclass Solution {\npublic:\n   bool check(vector<int>&nums,vector<vector<int>>&adj,int target)\n   {\n       int n=nums.size();\n       vector<int>te
\n# Code\n```\nclass Solution {\npublic:\n   bool check(vector<int>&nums,vector<vector<int>>&adj,int target)\n   {\n       int n=nums.size();\n       vector<int>temp(n,0);\n       if (traverse(0,nums,adj,target,temp)==0) return true;\n       return false;\n   }\n   \n   int traverse(int node,vector<int>&nums,vector<vector<int>>&adj,int target,vector<int>&temp)\n   {\n       temp[node]=nums[node];\n       for (auto it:adj[node])\n       {\n           if (temp[it]) continue;\n           temp[node]+=traverse(it,nums,adj,target,temp);\n           if (temp[node]>target) return 1e5;\n       }\n       if (temp[node]==target) return 0;\n       return temp[node];\n   }\n\n\n    int componentValue(vector<int>& nums, vector<vector<int>>& edges) \n    {\n        int n=nums.size();\n        vector<vector<int>>adj(n);\n        for (auto it:edges)\n        {\n           adj[it[0]].push_back(it[1]);\n           adj[it[1]].push_back(it[0]);\n        }\n        int sum=0;\n        for (auto it:nums) sum+=it;\n        for (int i=n;i>1;i--)\n        {\n           if (sum%i) continue;\n           if (check(nums,adj,sum/i)) return i-1;\n        }\n        return 0;\n    }\n};\n```
['C++']