[C++] || Code for beginners || Easy understanding DFS
\nclass Solution {\nprivate:\n    list<int>* adj;\npublic:\n    vector<int> Divisors(int n){\n        vector<int> G,L;\n        for(int i=1;i<=sqrt(n);i++){\n  
```\nclass Solution {\nprivate:\n    list<int>* adj;\npublic:\n    vector<int> Divisors(int n){\n        vector<int> G,L;\n        for(int i=1;i<=sqrt(n);i++){\n            if(n%i==0){\n                if(n/i==i){\n                    L.push_back(i);\n                }\n                else{\n                    G.push_back(n/i);\n                    L.push_back(i);\n                }\n            }\n        }\n        vector<int> res=L;\n        for(int i=G.size()-1;i>=0;i--){\n            res.push_back(G[i]);\n        }\n        return res; // returns sorted output\n    }  \n    \n    int validate(int node, int sum, vector<int>& nums, int par){\n        int currsum=nums[node];\n        for(auto nei: adj[node]){\n            if(par==nei){\n                continue;\n            }\n            currsum+=validate(nei,sum,nums,node);\n            if(currsum>sum){\n                return INT_MAX/2;\n            }\n        }\n        if(currsum==sum){ // erasing edge and hence return 0\n            return 0;\n        }\n        return currsum;\n    }\n    \n    int componentValue(vector<int>& nums, vector<vector<int>>& edges) {\n        int sum=accumulate(nums.begin(),nums.end(),0);\n        vector<int> div=Divisors(sum);\n        int n=nums.size();\n        adj=new list<int>[n];\n        for(auto edge: edges){\n            adj[edge[0]].push_back(edge[1]);\n            adj[edge[1]].push_back(edge[0]);\n        }\n        for(auto d: div){\n            if(validate(0,d,nums,-1)==0){\n                return sum/d-1;\n            }\n        }\n        return 0;\n    }\n};\n```
['Depth-First Search', 'C']