Simple Python | Union Find
\nclass Solution:\n    def distanceLimitedPathsExist(self, n: int, A: List[List[int]], B: List[List[int]]) -> List[bool]:\n        par = {}\n        A.sort(key 
```\nclass Solution:\n    def distanceLimitedPathsExist(self, n: int, A: List[List[int]], B: List[List[int]]) -> List[bool]:\n        par = {}\n        A.sort(key = lambda x: x[2])\n        \n        for i, query in enumerate(B):\n            query.append(i)\n        B.sort(key = lambda x: x[2])\n        \n        def find(a):\n            par.setdefault(a, a)\n            if par[a] != a:\n                par[a] = find(par[a])\n            return par[a]\n        \n        def union(a, b):\n            par.setdefault(a, a)\n            par.setdefault(b, b)\n            par[find(a)] = par[find(b)]\n        \n        ans = [False]*len(B)\n        i = 0\n        for a, b, lim, idx in B:\n            while i < len(A) and A[i][2] < lim:\n                union(A[i][0], A[i][1])\n                i += 1\n            \n            if find(a) == find(b):\n                ans[idx] = True\n        return ans\n ```
['Python3']