Python: build graph from smallest dist to bigger
Sort queries by limit\n2. Sort edges by dist\n3. Iterate over queries as l:\n3.1. Connect all nodes that have edges with d < l. \n3.2. Check the query\'s p and 
1. Sort *queries* by `l`imit\n2. Sort *edges* by `d`ist\n3. Iterate over `queries` as `l`:\n3.1. Connect all nodes that have edges with `d` < `l`. \n3.2. Check the query\'s `p` and `q` belong to the same `component`.\n4. Repeat for all queries\n\n```\nclass Solution:\n    def distanceLimitedPathsExist(self, n: int, edgeList: List[List[int]], queries: List[List[int]]) -> List[bool]:\n        parents = defaultdict(lambda: None)\n        sizes = defaultdict(int)\n        \n        def find(a):\n            if a not in parents:\n                parents[a] = a\n                sizes[a] = 1\n                return a\n\n            root = a\n            while parents[root] != root:\n                root = parents[root]\n\n            while parents[a] != a:\n                nxt = parents[a]\n                parents[a] = root\n                a = nxt\n            \n            return root\n        \n        def union(a,b):\n            roota = find(a)\n            rootb = find(b)\n            \n            if roota == rootb:\n                return\n            \n            if sizes[roota] > sizes[rootb]:\n                sizes[roota] += sizes[rootb]\n                sizes[rootb] = 0\n                parents[rootb] = roota\n            else:\n                sizes[rootb] += sizes[roota]\n                sizes[roota] = 0\n                parents[roota] = rootb\n        \n        Q, E = len(queries), len(edgeList)\n                \n        edgeList.sort(key=lambda x: x[2])\n        queries = sorted(((u,v,l,i) for i,(u,v,l) in enumerate(queries)), key=lambda x: x[2])\n        \n        res = [False] * Q\n        e_idx = 0\n        for p, q, l, i in queries:\n            while e_idx < E and edgeList[e_idx][2] < l:\n                u, v, _ = edgeList[e_idx]\n                union(u, v)\n                e_idx += 1\n            res[i] = find(p) == find(q)\n        return res\n```
['Graph', 'Python']