[Python] DFS - Clean & Concise
\u2714\uFE0F Solution 1: DFS\npython\nclass Solution:\n    def minMalwareSpread(self, matrix: List[List[int]], initial: List[int]) -> int:\n        n = len(matr
**\u2714\uFE0F Solution 1: DFS**\n```python\nclass Solution:\n    def minMalwareSpread(self, matrix: List[List[int]], initial: List[int]) -> int:\n        n = len(matrix)\n        graph = defaultdict(list)\n        for i in range(n):\n            for j in range(i + 1, n):\n                if matrix[i][j] == 0: continue\n                graph[i].append(j)\n                graph[j].append(i)\n\n        def dfs(u, seen):\n            if u in seen: return 0\n            totalNodes = 1\n            seen.add(u)\n            for v in graph[u]:\n                totalNodes += dfs(v, seen)\n            return totalNodes\n\n        best = [-1, n + 1]  # node, cnt\n        for removed in initial:\n            totalNodes = 0\n            seen = {removed}\n            for other in initial:\n                totalNodes += dfs(other, seen)\n\n            if totalNodes < best[1] or totalNodes == best[1] and best[0] > removed:\n                best = [removed, totalNodes]\n\n        return best[0]\n```\nComplexity:\n- Time: `O(K * (E + V))` ~ `O(K * (N^2 + N))` ~ `O(K * N^2)`, where `N <= 300` is number of vertices, `K < N` is length of `initial` array.\n- Space: `O(N^2)`
[]