Simple DFS  
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->
    DFS


# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->


- Space complexity:

# Code
```cpp []
class Solution {
public: 
    int ans=0;
    int dfs(int i,vector<int>adj[],vector<int>&v,vector<int>&nums,int k)
    {
        v[i]=1;
        int s=nums[i];
        for(auto it:adj[i])
        {   
            if(!v[it])
            {
                s+=dfs(it,adj,v,nums,k);
            }
        }
        if(s==k) 
        {
            ans++;
            return 0;
        }
        return s;
    }
    int componentValue(vector<int>& nums, vector<vector<int>>& e) {
        if(e.size()==0) return 0;
        const int n=nums.size();
        vector<int>adj[n];
        for(int i=0;i<e.size();i++)
        {
            adj[e[i][0]].push_back(e[i][1]);
            adj[e[i][1]].push_back(e[i][0]);
        }
        int k=-1e9;
        int s=0;
        for(int i=0;i<n;i++)
        {
            s+=nums[i];
            k=max(k,nums[i]);
        }
        vector<int>fac;
        for(int i=1;i*i<=s;i++)
        {
            if(s%i==0) 
            {
                fac.push_back(i);
                if(s/i!=i) fac.push_back(s/i);
            }
        }
        sort(fac.begin(),fac.end());
        
        for(int i=0;i<fac.size();i++)
        {
            if(fac[i]>=k)
            {
                ans=0;
                vector<int>v(n,0);
                dfs(0,adj,v,nums,fac[i]);
                if(ans>0 && ans*fac[i]==s) 
                {
                    return ans-1;
                }
            }
        }
        return 0;
    }
};

```
['C++']