Python3 beats 87.42% 🚀🚀 quibler7
Code\n\nclass Solution:\n    def distanceLimitedPathsExist(self, n: int, edgeList: List[List[int]], queries: List[List[int]]) -> List[bool]:\n        \n        
# Code\n```\nclass Solution:\n    def distanceLimitedPathsExist(self, n: int, edgeList: List[List[int]], queries: List[List[int]]) -> List[bool]:\n        \n        parent = [i for i in range(n+1)]\n    \n        rank = [0 for i in range(n+1)]\n\n        def find(parent, x):\n\n            if parent[x] == x:\n                return x\n            parent[x] = find(parent, parent[x])\n            return parent[x]\n\n        def union(parent, a, b):\n\n            a = find(parent, a)\n            b = find(parent, b)\n\n            if a == b:\n                return \n\n            if rank[a] < rank[b]:\n                parent[a] = b\n            elif rank[a] > rank[b]:\n                parent[b] = a\n            else:\n                parent[b] = a\n                rank[a] += 1\n                \n        edgeList.sort(key = lambda x: x[2])\n        res = [0] * len(queries)\n        queries = [[i, ch] for i, ch in enumerate(queries)]\n        queries.sort(key = lambda x: x[1][2])\n        \n        ind = 0\n        for i, (a, b, w) in queries:\n            \n            while ind < len(edgeList) and edgeList[ind][2] < w:\n                union(parent, edgeList[ind][0], edgeList[ind][1])\n                ind += 1\n                \n            res[i] = find(parent, a) == find(parent, b)\n        return res\n```
['Python3']