Union Find 146 / 160 test cases passed. Why?
Any buddy give me some advise? Why Union Find does\'t work!\n\n\nclass Union:\n    def __init__ (self,n):\n        self.root = [i for i in range(n)]\n        se
Any buddy give me some advise? Why Union Find does\'t work!\n```\n\nclass Union:\n    def __init__ (self,n):\n        self.root = [i for i in range(n)]\n        self.rank = [1 for i in range(n)]\n        self.count = n\n            \n    def union(self,x,y):\n        rootX = self.find(x)\n        rootY = self.find(y)\n        if rootX != rootY:\n            if self.rank[x]>self.rank[y]:\n                self.root[rootY] = rootX\n            elif self.rank[x]<self.rank[y]:\n                self.root[rootX] = rootY\n            else:\n                self.root[rootY]=rootX\n                self.rank[rootX] += 1 \n            self.count -= 1\n        \n                \n    def find(self,x):\n        if self.root[x]==x:\n            return x\n        self.root[x]=self.find(self.root[x])\n        return self.root[x]\n\n\nclass Solution:\n    def maximumDetonation(self, bombs: List[List[int]]) -> int:\n        l = len(bombs)\n        u = Union(l)\n        \n        def distance (p1,p2):\n            return ((p1[0]-p2[0])**2 + (p1[1]-p2[1])**2)**0.5\n        \n        for i in range(l):\n            for j in range(l):\n                # if i==j:\n                #     continue\n                di = distance(bombs[i],bombs[j])\n                # print(di)\n                if bombs[i][2]>=di or bombs[j][2]>=di:\n                    u.union(i,j)\n\n        print(u.root)\n        mapping = {}\n        for i in u.root:\n            mapping[i] = mapping.get(i,0) + 1\n        return max(mapping.values())\n\n```
['Union Find']