[C++] DFS
```\nclass Solution {\npublic:\n    int componentValue(vector& nums, vector>& edges) {\n        int size = nums.size();\n        int sum = 0;\n        for(int n
```\nclass Solution {\npublic:\n    int componentValue(vector<int>& nums, vector<vector<int>>& edges) {\n        int size = nums.size();\n        int sum = 0;\n        for(int num: nums) sum += num;\n            \n        vector<vector<int>> e(size);\n        for(vector<int>& edge: edges) {\n            e[edge[0]].push_back(edge[1]);\n            e[edge[1]].push_back(edge[0]);\n        }\n        \n        vector<int> visited(size, 0);\n        bool res;\n        int target;\n        function<int(int)> dfs = [&](int startNode) {\n            if(!res) return 0;\n            \n            visited[startNode] = target;\n            int sum = 0;\n            for(int nextNode: e[startNode]) {\n                if(visited[nextNode] != target) sum += dfs(nextNode);\n            }\n            \n            sum += nums[startNode];\n            if(sum > target) res = false;\n            return sum >= target ? 0 : sum;\n        };\n        \n        for(int div = size; div >= 2; div--) {\n            if(sum % div) continue;\n            \n            res = true;\n            target = sum / div;\n            dfs(0);\n            if(res) return div - 1;\n        }\n        \n        return 0;\n    }\n};
[]