Easy Python Union Find
\n    def findCircleNum(self, M):\n        """\n        :type M: List[List[int]]\n        :rtype: int\n        """\n        def find(x):\n            if x != pa
```\n    def findCircleNum(self, M):\n        """\n        :type M: List[List[int]]\n        :rtype: int\n        """\n        def find(x):\n            if x != parents[x]:\n                parents[x] = find(parents[x])\n            return parents[x]    \n        def union(x, y):\n            parents[find(x)] = find(y)\n        n = len(M)\n        parents = list(range(n))\n        for i in range(len(M)):\n            for j in range(len(M[i])):\n                if M[i][j]:\n                    union(i, j)\n        circle = set(find(i) for i in range(n))            \n        return len(circle) \n```
[]