Neetcode's "Number of Connected Components in Graph" union find
\nclass Solution:\n    def findCircleNum(self, isConnected: List[List[int]]) -> int:\n        rows = len(isConnected)\n        cols = len(isConnected[0])\n     
```\nclass Solution:\n    def findCircleNum(self, isConnected: List[List[int]]) -> int:\n        rows = len(isConnected)\n        cols = len(isConnected[0])\n        \n        amount = len(isConnected)\n        \n        parents = [i for i in range(amount)]\n        rank = [1] * amount\n        \n        def find(n1):\n            p = n1\n            while p != parents[p]:\n                parents[p] = parents[parents[p]]\n                p = parents[p]\n            return p\n        \n        def union(n1, n2):\n            p1, p2 = find(n1), find(n2)\n            if p1 == p2:\n                return 0\n            if rank[p1] >= rank[p2]:\n                rank[p1] += rank[p2]\n                parents[p2] = p1\n            else:\n                rank[p2] += rank[p1]\n                parents[p1] = p2\n            return 1\n        \n        for r in range(rows):\n            for c in range(cols):\n                if r != c and isConnected[r][c] == 1:\n                    amount -= union(r, c)\n                    isConnected[r][c] = 0\n                    isConnected[c][r] = 0\n                    \n        return amount\n```
['Union Find', 'Python']