Python, Union-Find
\ndef findCircleNum(self, isConnected: List[List[int]]) -> int:\n\tn = len(isConnected)\n\troots = list(range(n))\n\tsizes = [1] * n\n\n\tdef find_parent(a):\n\
```\ndef findCircleNum(self, isConnected: List[List[int]]) -> int:\n\tn = len(isConnected)\n\troots = list(range(n))\n\tsizes = [1] * n\n\n\tdef find_parent(a):\n\t\tif roots[a] != a:\n\t\t\troots[a] = find_parent(roots[a])\n\t\treturn roots[a]\n\n\tdef union(a, b):\n\t\tra = find_parent(a)\n\t\trb = find_parent(b)\n\n\t\tif ra == rb: return\n\t\trbig, rsmall = (ra, rb) if sizes[ra] > sizes[rb] else (rb, ra)\n\n\t\troots[rsmall] = rbig\n\t\tsizes[rbig] += sizes[rsmall]\n\n\tfor i in range(n):\n\t\tfor j in range(i+1, n):\n\t\t\tif isConnected[i][j]:\n\t\t\t\tunion(i, j)\n\n\treturn len(set(find_parent(i) for i in range(n)))\n```
['Union Find', 'Python', 'Python3']