Detailed and clear solution
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```\nclass Solution:\n    def containVirus(self, isInfected: List[List[int]]) -> int:\n        \'\'\'\n        isInfected[r][c]:\n            0 : Uninfected\n            1 : Infected\n            2 : Infected & restricted\n        \'\'\'\n        m = len(isInfected)\n        n = len(isInfected[0])\n\n        borders = 0\n        threatened = 0\n        def dfs(r, c, id):\n            nonlocal borders, threatened\n            if r < 0 or r>=m or c < 0 or c>=n:\n                return\n\n            if isInfected[r][c] == 1:\n                if visited[r][c] == 0:\n                    visited[r][c] = 1\n                    dfs(r-1, c, id)\n                    dfs(r+1, c, id)\n                    dfs(r, c-1, id)\n                    dfs(r, c+1, id)\n                else:\n                    pass\n            elif isInfected[r][c] == 0:\n                if visited[r][c] == id:\n                    borders += 1\n                else:\n                    borders += 1\n                    threatened += 1\n                    visited[r][c] = id\n        \n        def flood(r, c, find, repl):\n            if r < 0 or r>=m or c < 0 or c>=n or isInfected[r][c] != find:\n                return\n            isInfected[r][c] = repl\n            flood(r-1, c, find, repl)\n            flood(r+1, c, find, repl)\n            flood(r, c-1, find, repl)\n            flood(r, c+1, find, repl)\n        \n        def expand(r, c, id):\n            if r < 0 or r>=m or c < 0 or c>=n or visited[r][c] == 1:\n                return\n            visited[r][c] = 1\n            if isInfected[r][c] == 0:\n                isInfected[r][c] = 1\n            elif isInfected[r][c] == 1:\n                expand(r+1, c, id)\n                expand(r-1, c, id)\n                expand(r, c-1, id)\n                expand(r, c+1, id)   \n\n        total_walls = 0\n\n        while True:\n            # Day ---------------------------------------------------\n            max_th = 0\n            max_th_loc = (None, None)\n            max_th_border = 0\n            id = 3\n            visited = [[0] * n for _ in range(m)]\n\n            for r in range(m):\n                for c in range(n):\n                    if isInfected[r][c]==1 and visited[r][c] == 0:\n                        \n                        borders = 0\n                        threatened = 0\n                        dfs(r, c, id)\n                        id += 1\n                        if threatened > max_th:\n                            max_th = threatened\n                            max_th_loc = r, c\n                            max_th_border = borders\n            \n            if max_th == 0:\n                break\n            total_walls += max_th_border\n            # Restrict bordered region by making them dormant\n            flood(*max_th_loc, 1, 2)\n\n            # Night -------------------------------------------------\n\n            visited = [[0] * n for _ in range(m)]\n            for r in range(m):\n                for c in range(n):\n                    if isInfected[r][c]==1 and visited[r][c] == 0:\n                        expand(r, c, id)\n                        id += 1\n\n        return total_walls\n\n\n\n\n\n\n```
['Python3']