C++
(```)  class Solution {\npublic:\n    \n    vector> graph;\n    \n    int dfs(int src, int parent, int target, vector& nums)\n    {\n        int sum = nums[src]
(```)  class Solution {\npublic:\n    \n    vector<vector<int>> graph;\n    \n    int dfs(int src, int parent, int target, vector<int>& nums)\n    {\n        int sum = nums[src];\n        \n        for(auto &x: graph[src])\n        {\n            if(x != parent)\n            {\n                sum += dfs(x,src,target, nums);\n            }\n        }\n        \n        if(sum == target)\n        {\n            return 0;\n        }\n        \n        return sum;\n    }\n    int componentValue(vector<int>& nums, vector<vector<int>>& edges) \n    {\n        \n        int n =  nums.size();\n        \n        graph.resize(n);\n        \n        for(auto &x: edges)\n        {\n            graph[x[0]].push_back(x[1]);\n            graph[x[1]].push_back(x[0]);\n        }\n        \n        int sum = accumulate(nums.begin(),nums.end(), 0);\n        \n        for(int i=sum; i>=1; i--)\n        {\n            if(sum % i == 0)\n            {\n                if(dfs(0,-1, sum/ i, nums) == 0)\n                {\n                    return i-1;\n                }\n            }\n        }\n        \n        return 0;\n    }\n};
[]