Simple Java Solution
\nclass Solution {\n    class Pair{\n        int node;\n        int val;\n        Pair(int node,int val){\n            this.node=node;\n            this.val=val
```\nclass Solution {\n    class Pair{\n        int node;\n        int val;\n        Pair(int node,int val){\n            this.node=node;\n            this.val=val;\n        }\n    }\n    public int componentValue(int[] nums, int[][] edges) {\n        int n=nums.length;\n        int sum=0;\n        List<List<Integer>> adjList=new ArrayList<>();\n        int[] degree=new int[n];\n        for(int i=0;i<n;i++){\n            sum=sum+nums[i];\n            adjList.add(new ArrayList<>());\n        }\n        for(int[] edge:edges){\n            adjList.get(edge[0]).add(edge[1]);\n            adjList.get(edge[1]).add(edge[0]);\n            degree[edge[0]]++;\n            degree[edge[1]]++;\n        }\n        List<Integer> factors=new ArrayList<>();\n        for(int i=1;i<=(int)Math.sqrt(sum);i++){\n            if(sum%i==0){\n                factors.add(i);\n                factors.add(sum/i);\n            }\n        }\n        Collections.sort(factors);\n        for(int factor:factors){\n            if(sum%factor!=0) continue;\n            Queue<Pair> q=new LinkedList<>();\n            int[] visited=new int[n];\n            int[] numsCopy=new int[n];\n            int[] degreeCopy=new int[n];\n            for(int j=0;j<n;j++){\n                numsCopy[j]=nums[j];\n                degreeCopy[j]=degree[j];\n                if(degreeCopy[j]==1){\n                    q.add(new Pair(j,numsCopy[j]));\n                    visited[j]=1;\n                    \n                }      \n            }\n            int component=0;\n            int count=0;\n            while(!q.isEmpty()){\n                Pair pair=q.remove();\n                count++;\n                if(numsCopy[pair.node]==factor){\n                    component++;\n                }\n                if(numsCopy[pair.node]>factor) break;\n                for(int parent:adjList.get(pair.node)){\n                    if(numsCopy[pair.node]<factor){\n                        numsCopy[parent]=numsCopy[parent]+numsCopy[pair.node];\n                    }                    \n                    if(visited[parent]==0){\n                        degreeCopy[parent]--;\n                        if(degreeCopy[parent]==1){\n                            q.add(new Pair(parent,numsCopy[parent]));\n                            visited[parent]=1;\n                        }\n                    }\n                }\n                if(count==n) return component-1;\n            }\n        }\n        return 0;\n    }\n}\n```
['Graph', 'Java']