C++ DFS concise
```\n    int componentValue(vector& nums, vector>& edges) {\n        const auto sum = accumulate(nums.begin(), nums.end(), 0); \n        vector> g(nums.size());
```\n    int componentValue(vector<int>& nums, vector<vector<int>>& edges) {\n        const auto sum = accumulate(nums.begin(), nums.end(), 0); \n        vector<vector<int>> g(nums.size());\n        for (auto& e:edges) g[e[0]].push_back(e[1]), g[e[1]].push_back(e[0]);        \n        for (int d=1;d<= sum/2; d++)\n            if (sum % d == 0 && dfs(g, nums, 0, -1, d) == 0) return sum/d - 1;\n        return 0;\n    }\n    \n    int dfs(const vector<vector<int>>& g, const vector<int>& nums, int i, int par, int d){\n        int sum = nums[i];\n        for (auto j : g[i]) {\n            if (j == par) continue;\n            if (int x = dfs(g, nums, j, i, d); x==-1) return -1; //impossible\n            else sum += x;\n        }\n        if (sum > d) return -1;\n        return sum == d ? 0 : sum;\n    }
[]