Simple Explained Solution
\n\nclass Solution {\npublic:\n    int m, n;\n    int ans = 0;\n    \n    // -1 means disinfected\n    int color = 2;\n    \n    // for perimeter calculation we
\n```\nclass Solution {\npublic:\n    int m, n;\n    int ans = 0;\n    \n    // -1 means disinfected\n    int color = 2;\n    \n    // for perimeter calculation we cannot go to cells marked -1 but we can goto all other cells\n    int perimeter = 0;\n    \n    // we can go to cells marked as 0 only\n    // this will store the area being threatened\n    int areat = 0;\n    \n    int containVirus(vector<vector<int>>& a) {\n        m = a.size();\n        n = a[0].size();\n\n        while(1){\n            int restrictX, restrictY;\n            int big = -1;\n            for(int i = 0 ; i < m ; i++){\n                for(int j = 0 ; j < n ; j++){\n                    if(a[i][j] == color-1){\n                        \n                        //capture this region and color it with color\n                        dfs(a, i, j);\n                        areat = 0;\n                        set<pair<int, int>> visited;\n                        calculateAreat(a, i, j, visited);\n                        //calculateAreat marks the region with -2 so we will restore\n                        restore(a, i, j);\n                        if(big < areat){\n                            big = areat;\n                            restrictX = i;\n                            restrictY = j;\n                        }\n                    }\n                }\n            }\n            \n            if(big != -1){\n                perimeter = 0;\n                calculatePerimeter(a, restrictX, restrictY);\n                ans += perimeter;\n                int temp = color;\n                color = -1;\n                // disinfect this region by marking as -1\n                restore(a, restrictX, restrictY);\n                \n                color = temp+1;\n                for(int i = 0 ; i < m ; i++){\n                    for(int j = 0 ; j < n ; j++){\n                        if(a[i][j] == color-1){\n                            expand(a, i, j, a[i][j]);\n                            // expand marks the region as -2 so we restore it to color\n                            restore(a, i, j);\n                        }\n                    }\n                }\n                color++;\n            }\n            else{\n                break;\n            }\n        }\n        \n        return ans;\n    }\n    \n    void expand(vector<vector<int>>& a, int x, int y, int currcolor){\n        if(x < 0 || y < 0 || x >= m || y >= n){\n            return;\n        }\n        \n        if(a[x][y] == 0){\n            a[x][y] = -2;\n            return;\n        }\n        \n        if(a[x][y] == -2 || a[x][y] == -1 || a[x][y] != currcolor){\n            return;\n        }\n        \n        a[x][y] = -2;\n        expand(a, x+1, y, currcolor);\n        expand(a, x, y+1, currcolor);\n        expand(a, x, y-1, currcolor);\n        expand(a, x-1, y, currcolor);\n    }\n    \n    void dfs(vector<vector<int>>& a, int x, int y){\n        if(x < 0 || y < 0 || x >= m || y >= n || a[x][y] == 0 || a[x][y] == -1){\n            return;\n        }\n        \n        if(a[x][y] == color){\n            return;\n        }\n        \n        a[x][y] = color;\n        dfs(a, x+1, y);\n        dfs(a, x, y+1);\n        dfs(a, x, y-1);\n        dfs(a, x-1, y);\n    }\n    \n    void restore(vector<vector<int>>& a, int x, int y){\n        if(x < 0 || y < 0 || x >= m || y >= n || a[x][y] == 0 || a[x][y] != -2){\n            return;\n        }\n        \n        a[x][y] = color;\n        restore(a, x+1, y);\n        restore(a, x, y+1);\n        restore(a, x, y-1);\n        restore(a, x-1, y);\n    }\n    \n    // -2 is under processing\n    void calculatePerimeter(vector<vector<int>>& a, int x, int y){\n        if(x < 0 || y < 0 || x >= m || y >= n || a[x][y] == -1 || a[x][y] == -2){\n            return;\n        }\n        \n        if(a[x][y] == 0){\n            perimeter++;\n            return;\n        }\n        \n        a[x][y] = -2;\n        calculatePerimeter(a, x+1, y);\n        calculatePerimeter(a, x, y+1);\n        calculatePerimeter(a, x, y-1);\n        calculatePerimeter(a, x-1, y);\n    }\n    \n    // -2 is under processing\n    void calculateAreat(vector<vector<int>>& a, int x, int y, set<pair<int, int>> &visited){\n        if(x < 0 || y < 0 || x >= m || y >= n || a[x][y] == -2 \n           || a[x][y] == -1 || visited.count({x,y})){\n            return;\n        }\n        \n        if(a[x][y] == 0){\n            visited.insert({x,y});\n            areat++;\n            return;\n        }\n        \n        a[x][y] = -2;\n        calculateAreat(a, x+1, y, visited);\n        calculateAreat(a, x, y+1, visited);\n        calculateAreat(a, x, y-1, visited);\n        calculateAreat(a, x-1, y, visited);\n    }\n    \n    void print(vector<vector<int>> &a){\n        for(int i = 0 ; i < m ; i++){\n            for(int j = 0 ; j < n ; j++){\n                cout<<a[i][j]<<"\\t";\n            }\n            cout<<endl;\n        }\n        cout<<endl;\n    }\n};\n```
['C++', 'Scala', 'Ruby', 'Kotlin', 'JavaScript']