Python (Simple DFS)
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:\n    def componentValue(self, nums, edges):\n        if not edges:\n            return 0\n\n        n, dict1, result = len(nums), defaultdict(list), sum(nums)\n\n        for i,j in edges:\n            dict1[i].append(j)\n            dict1[j].append(i)\n\n        def function(node,parent,i):\n            total = nums[node]\n\n            for neighbor in dict1[node]:\n                if neighbor != parent:\n                    total += function(neighbor,node,i)\n\n            return total if total != i else 0\n\n        for i in range(max(nums),result//min(nums)):\n            if result%i == 0 and function(0,-1,i) == 0:\n                return result//i - 1\n\n        return 0\n```
['Python3']