Python Tarjan + DFS
We use Tarjan to group strongly connected components than for each virus we remove it from our connected component and dfs over its neighbours where they are pa
We use Tarjan to group strongly connected components than for each virus we remove it from our connected component and dfs over its neighbours where they are part of the same original strongly connected component. If we see a virus we return 0 since that virus will take over that whole component group else we can return the count of components in that group. The idea is to mainly just split the strongly connected component and hope that the virus you removed was a bridge or the only virus in that group.\n\n```py\nclass Solution:\n    def minMalwareSpread(self, graph: List[List[int]], initial: List[int]) -> int:\n        def tarjan(i):\n            nonlocal idVal\n            \n            ids[i] = idVal\n            initLow[i] = idVal\n            stack.append(i)\n            inStack[i] = True\n            idVal += 1\n            \n            for j in adj[i]:\n                \n                if ids[j] == -1:\n                    tarjan(j)\n                \n                if inStack[j]:\n                    initLow[i] = min(initLow[i], initLow[j])\n            \n            #we found the root of our connected component\n            if initLow[i] == ids[i]:\n                \n                while stack:\n                    val = stack.pop()\n                    initLow[val] = ids[i]\n                    inStack[val] = False\n                    if val == ids[i]:\n                        break\n                    \n                \n        def dfs(i,x):\n            nonlocal idVal\n            \n            if i in initial:\n                return [0,True]\n            virus = False    \n            ids[i] = idVal\n            idVal += 1\n            res = 0\n            for j in adj[i]:\n                \n                if j == x or initLow[i] != initLow[j]:\n                    continue\n                    \n                if ids[j] == -1:\n                    r,v = dfs(j,x)\n                    virus = virus or v\n                    res += r\n            \n            return [res + 1,virus]\n                    \n                \n \n        \n        n = len(graph)\n        stack = []\n        inStack = [False] * n\n        ids = [-1] * n\n        initLow = [-1] * n\n        idVal = 0\n        \n        initial = set(initial)\n        adj = defaultdict(list)\n        \n        for i in range(len(graph)):\n            for j in range(len(graph[i])):\n                if graph[i][j] == 1 and i != j: \n                    adj[i].append(j)\n        \n        \n        for i in range(len(graph)):\n            if ids[i] == -1:\n                tarjan(i)\n        \n       \n        best = [-1,-1]\n        for i in sorted(initial):\n            ids = [-1] * n\n            idVal = 0\n            curBest = 0\n            for v in adj[i]:\n                #make sure they are within the same connected component\n                if ids[v] == -1 and initLow[i] == initLow[v]:\n                    score,virus = dfs(v,i)\n                    if not virus:\n                        curBest += score\n                        \n            if curBest > best[0]:\n                best = [curBest, i]\n            \n\n        return best[1]
['Depth-First Search', 'Python']