Using Dsu
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```java []\nclass Solution {\n    public static int find(int i,int[] parent){\n        if(i==parent[i]){\n            return i;\n        }\n        return parent[i]=find(parent[i],parent);\n    }\n    public static void Union(int x,int y,int[] parent){\n        int i=find(x,parent);\n        int j=find(y,parent);\n        parent[i]=j;\n        return;\n    }\n    public static int Dsu(int[][] graph,int[] initial,int rem){\n        int[] parent=new int[graph.length];\n        \n        for(int i=0;i<graph.length;i++){\n            parent[i]=i;\n        }\n\n        for(int i=0;i<graph.length;i++){\n            for(int j=i+1;j<graph.length;j++){\n                if(i==rem || j==rem || graph[i][j]==0){\n                    continue;\n                }\n                else{\n                    Union(i,j,parent);\n                }\n            }\n        }\n        HashSet<Integer> infected=new HashSet<>();\n        for(int i=0;i<initial.length;i++){\n            if(initial[i]==rem) continue;\n            else{\n                infected.add(find(initial[i],parent));\n            }\n        }\n        int count=0;\n        for(int i=0;i<graph.length;i++){\n            if(infected.contains(find(i,parent))){\n                count++;\n            }\n        }\n        return count;\n    }\n    public int minMalwareSpread(int[][] graph, int[] initial) {\n        int min_val=Integer.MAX_VALUE;\n        int min_index=-1;\n        Arrays.sort(initial);\n        for(int i=0;i<initial.length;i++){\n            int val=Dsu(graph,initial,initial[i]);\n            if(val<min_val){\n                min_val=val;\n                min_index=initial[i];\n            }\n        }\n        return min_index;\n    }\n}\n```
['Java']