Python Union Find solution
\nclass Solution:\n    def findCircleNum(self, M):\n        """\n        :type M: List[List[int]]\n        :rtype: int\n        """\n        def find(node):\n  
```\nclass Solution:\n    def findCircleNum(self, M):\n        """\n        :type M: List[List[int]]\n        :rtype: int\n        """\n        def find(node):\n            if circles[node] == node: return node\n            root = find(circles[node])\n            circles[node] = root\n            return root\n        \n        n = len(M)\n        circles = {x:x for x in range(n)}\n        num = n\n        for i in range(n):\n            for j in range(i, n):\n                if i != j and M[i][j] == 1 and find(i) != find(j):\n                    circles[find(i)] = find(j)   \n                    \n        return sum([1 for k, v in circles.items() if k == v])\n ```
[]