Solution
C++ []\nclass Solution {\n    bool vis[300];\npublic:\n    void dfs(const vector<vector<int>>&v,int node,const int nhi_dekhna,int &ans)\n    {\n        vis[node
```C++ []\nclass Solution {\n    bool vis[300];\npublic:\n    void dfs(const vector<vector<int>>&v,int node,const int nhi_dekhna,int &ans)\n    {\n        vis[node] = true;\n        ++ans;\n        for(auto &x : v[node])\n            if(!vis[x] and x != nhi_dekhna)\n                dfs(v,x,nhi_dekhna,ans);\n    }   \n    int minMalwareSpread(vector<vector<int>>& graph, vector<int>& initial) {\n        int n = graph.size();\n        vector<vector<int>> v(n);\n        for(int i = 0 ; i < n ; ++i)\n            for(int j = 0 ; j < n ; ++j)\n                if(graph[i][j] == 1 and i != j)\n                    v[i].push_back(j);\n        sort(initial.begin(),initial.end());\n        int res = 1e9;\n        int res1 = initial[0];\n        for(auto &x : initial)\n        {\n            int ans = 0;\n            memset(vis,false,sizeof vis);\n            for(auto &y : initial)\n            {\n                if(x != y and !vis[y])\n                    dfs(v,y,x,ans);\n            }\n            if(ans < res)\n            {\n                res1 = x;\n                res = ans;\n            }\n        }\n        return res1;\n    }\n};\n```\n\n```Python3 []\nclass Solution:\n    def minMalwareSpread(self, graph: List[List[int]], initial: List[int]) -> int:\n        N = len(graph)\n        uf = UF(N)\n\n        clean = set(range(N)) - set(initial)\n\n        for u, v in itertools.combinations(clean, 2):\n            if graph[u][v]:\n                uf.union(u,v)\n\n        infect_node = collections.defaultdict(set)\n        infected_by = collections.Counter()\n\n        ans = min(initial)\n        max = -1\n\n        for i in initial:\n            for c in clean:\n                if graph[i][c]==1:\n                    infect_node[i].add(uf.find(c))\n                    # infected[uf.find(c)] += [i]\n            for idx in infect_node[i]:\n                infected_by[idx] += 1\n        \n        size = collections.Counter(uf.find(i) for i in clean)\n\n        for key, nodes in infect_node.items():\n            cnt = 0\n            for node in nodes:\n                if infected_by[node]==1:\n                    cnt += size[node]\n            if cnt > max:\n                max = cnt\n                ans = key\n            elif cnt==max:\n                ans = min(ans, key)\n        return ans\n        \nclass UF:\n    def __init__(self, n):\n        self.parent = [-1]*n\n        self.unique = n\n\n    def find(self, a):\n        if self.parent[a]>=0:\n            self.parent[a] = self.find(self.parent[a])\n            return self.parent[a]\n        else:\n            return a\n        \n    def union(self, a, b):\n        pa = self.find(a)\n        pb = self.find(b)\n\n        if pa==pb: return False\n\n        if pa<pb:\n            self.parent[pa] += self.parent[pb]\n            self.parent[pb] = pa\n        else:\n            self.parent[pb] += self.parent[pa]\n            self.parent[pa] = pb\n        self.unique-=1\n        return True\n```\n\n```Java []\nclass Solution {\n    private int dfs(int[][] graph, int u, boolean[] visited, boolean[] infected) {\n        if(infected[u]) return 0;\n        visited[u] = true;\n        int count = 1;\n        for(int v = 0; v < graph[u].length; v++) {\n            if(!visited[v] && graph[u][v] == 1) {\n                int c = dfs(graph, v, visited, infected);\n                if(c == 0) {\n                    infected[u] = true;\n                    return 0;\n                }\n                count += c;\n            }\n        }\n        return count;\n    }\n    public int minMalwareSpread(int[][] graph, int[] initial) {\n        int n = graph.length, ans = initial[0], max = 0;\n        boolean[] infected = new boolean[n];\n        for(int u: initial) infected[u] = true;\n        for(int u: initial) {\n            boolean[] visited = new boolean[n];\n            visited[u] = true;\n            int count = 0;\n            for(int i = 0; i < n; i++) {\n                if(!visited[i] && graph[u][i] == 1) {\n                    count += dfs(graph, i, visited, infected);\n                }\n            }\n            if(count > max || count == max && u < ans) {\n                max = count;\n                ans = u;\n            }\n        }\n        return ans;\n    }\n}\n```\n
['C++', 'Java', 'Python3']