c++ 12ms O(N^2) recursion
\nclass Solution {\npublic:\n    void clear(vector<vector<int>>& M, int p) {\n        M[p][p] = 0;\n        for (int i = 0; i < M.size(); ++i) {\n            if
```\nclass Solution {\npublic:\n    void clear(vector<vector<int>>& M, int p) {\n        M[p][p] = 0;\n        for (int i = 0; i < M.size(); ++i) {\n            if (M[i][i] == 1 && M[p][i] == 1) clear(M, i);\n        }\n    }\n    \n    int findCircleNum(vector<vector<int>>& M) {\n        int cnt = 0;\n        for (int i = 0; i < M.size(); ++i) {\n            if (M[i][i] == 1) {\n                ++cnt;\n                clear(M, i);\n            }\n        }\n        return cnt;\n    }\n};\n```
[]