Java || Union Find || O(Vlog(V) + Elog(E)) || faster than  96.7%
\nclass Solution {\n    public boolean[] distanceLimitedPathsExist(int n, int[][] edgeList, int[][] queries) {\n        int queryLen = queries.length;\n        
```\nclass Solution {\n    public boolean[] distanceLimitedPathsExist(int n, int[][] edgeList, int[][] queries) {\n        int queryLen = queries.length;\n        int[][] queryWithIds = new int[queryLen][4];\n        \n        for (int i = 0; i < queryLen; i++) {\n            queryWithIds[i] = new int[] {\n              i, queries[i][0], queries[i][1], queries[i][2] \n            };\n        }\n        // sort quries by limit\n        Arrays.parallelSort(queryWithIds, (r1, r2) -> Integer.compare(r1[3], r2[3]));\n        // sort edges by dis\n        Arrays.parallelSort(edgeList, (r1, r2) -> Integer.compare(r1[2], r2[2]));\n        int edgeTop = 0;\n        boolean[] result = new boolean[queryLen];\n        // initialize UnionFind object\n        UnionFind uf = new UnionFind(n);\n        for (int i = 0; i < queryLen; i++) {\n            int limit = queryWithIds[i][3];\n            while (edgeTop < edgeList.length && edgeList[edgeTop][2] < limit) {\n                uf.union(edgeList[edgeTop][0], edgeList[edgeTop][1]);\n                edgeTop++;\n            }\n            result[queryWithIds[i][0]] = uf.find(queryWithIds[i][1]) == uf.find(queryWithIds[i][2]);\n        }\n        return result;\n    }\n    private static class UnionFind {\n        private int[] root;\n        private int[] rank;\n        public UnionFind(int n) {\n            this.root = new int[n];\n            this.rank = new int[n];\n            Arrays.fill(this.root, -1);\n        }\n        public int find(int target) {\n            if (root[target] == -1) return target;\n            return root[target] = find(root[target]);\n        }\n        public void union(int t1, int t2) {\n            int r1 = find(t1);\n            int r2 = find(t2);\n            if (r1 != r2) {\n                if (rank[r1] > rank[r2]) {\n                    root[r2] = r1;\n                } else if (rank[r2] > rank[r1]) {\n                    root[r1] = r2;\n                } else {\n                    root[r2] = r1;\n                    rank[r1]++;\n                }\n            }\n        }\n    }\n}\n```
['Union Find', 'Java']