python using bridge concept
\nclass Solution:\n    def minMalwareSpread(self, graph: List[List[int]], initial: List[int]) -> int:\n        n=len(graph)\n        visited=[-1]*n\n        res
```\nclass Solution:\n    def minMalwareSpread(self, graph: List[List[int]], initial: List[int]) -> int:\n        n=len(graph)\n        visited=[-1]*n\n        res=(-1,-inf)\n        infected=set(initial)\n        \n        def dfs(node,root_index):\n            if visited[node]!=-1:\n                return (True,0)\n\n            if node in infected and node!=initial[root_index]:\n                return (True,0)\n            visited[node]=root_index\n\n            ans=(False,1)\n\n            for to in range(n):\n                if node==to or graph[node][to]==0:\n                    continue\n                if visited[to] ==root_index:\n                    continue\n\n                \n                connected_to_other,m=dfs(to,root_index)\n                if connected_to_other and node!=initial[root_index]:\n                    return (True,0)\n                if connected_to_other==False:\n                    ans=(ans[0],m+ans[1])\n                if ans[0]:\n                    return ans\n            return ans\n        \n        for m in range(len(initial)):\n            connected_to_other,cnt=dfs(initial[m],m)\n            if connected_to_other:\n                continue\n                \n            if  cnt>res[1] or (cnt==res[1] and initial[m]< initial[res[0]]):\n                res=(m,cnt)\n        if res[0]==-1:\n            return initial[0]\n        return initial[res[0]]\n                \n\n```
['Depth-First Search', 'Python']