C++ || 91.96% Faster || 90.17% Less Space || Simple
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    #define ll long long\n\n    ll dfs(ll curr,ll par,ll target,vector<int>&nums,vector<ll>adj[],ll &count){\n        ll sum=nums[curr];\n        for(auto &x:adj[curr]){\n            if(x!=par){\n                sum+=dfs(x,curr,target,nums,adj,count);\n            }\n        }\n        if(sum==target){\n            count--;\n            return 0;\n        }\n        return sum;\n    }\n    \n    int componentValue(vector<int>& nums, vector<vector<int>>& edges) {\n        ll n=nums.size(),total=0;\n        for(auto &x:nums){\n            total+=x;\n        }\n        vector<ll>adj[n];\n        for(auto &x:edges){\n            adj[x[0]].push_back(x[1]);\n            adj[x[1]].push_back(x[0]);\n        }\n        set<ll>ss;\n        for(ll i=1;i*i<=total;i++){\n            if(total%i==0){\n                ss.insert(i);ss.insert(total/i);\n            }\n        }\n        for(auto &x:ss){\n            if(x==total){\n                continue;\n            }\n            ll count=total/x;\n            if(dfs(0,-1,x,nums,adj,count)==0 && count==0){\n                return (total/x)-1;\n            }\n        }\n        return 0;\n    }\n};\n```
['C++']