Easiest and Fastest solution (beats 100%)
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```cpp []\n#define ll long long \nint cnt=0;\nclass Solution {\npublic:\n   \n    ll dfs(vector<vector<int>> & g, vector<int> & nums, int val, int node, int par){\n        ll ans =nums[node];\n        for(auto v:g[node]){\n            if(v==par) continue;\n            ll subt=dfs(g,nums,val,v,node);\n            if(subt==val){\n                cnt++;\n            }\n            else{\n                ans+=subt;\n            }\n        }\n        return ans;\n    }\n    int componentValue(vector<int>& nums, vector<vector<int>>& edges) {\n        int n = nums.size();\n        vector<vector<int>> g(n);\n        for(auto e:edges){\n            g[e[0]].push_back(e[1]);\n            g[e[1]].push_back(e[0]);\n        }\n        vector<int> factors;\n        ll sum =0;\n        \n        \n        for(int i =0;i<n;i++){\n            sum+=nums[i];\n        }\n        int i;\n        // cout<<sum<<"\\n";\n        for(i=1;i*i<=sum;i++){\n            if(sum%i==0){\n                factors.push_back(i);\n            \n            }\n            \n        }\n        i--;\n        if(i*i==sum){\n            i--;\n        }\n        while(i>=1){\n            if(sum%i==0){\n                factors.push_back(sum/i);\n\n            }\n            i--;\n        }\n        ll ans =0;\n        for(int i =0;i<factors.size();i++){\n            cnt =0;\n            dfs(g,nums,factors[i],0,0);\n            // cout<<factors[i]<<" "<<cnt+1<<"\\n";\n            if(cnt+1==sum/factors[i]){\n                ans=cnt;\n                break;\n            }\n            // cout<<factors[i]<<"\\n";\n        }\n        return ans;\n\n        \n    }\n};\n```
['C++']