C++ | O(N log N) | Union Find
\n\tvoid merge(int a, int b, vector<int>& sets){\n        int x=find(a,sets),y=find(b,sets);\n        if(x!=y){\n            sets[x]=y;\n        }\n    }\n    i
```\n\tvoid merge(int a, int b, vector<int>& sets){\n        int x=find(a,sets),y=find(b,sets);\n        if(x!=y){\n            sets[x]=y;\n        }\n    }\n    int find(int a, vector<int>& sets){\n        return sets[a]==a?a:sets[a]=find(sets[a],sets);\n    }\n    vector<bool> distanceLimitedPathsExist(int n, vector<vector<int>>& edgeList, vector<vector<int>>& queries) {\n        sort(edgeList.begin(), edgeList.end(), [](vector<int> a, vector<int> b){\n            return a[2]<b[2];\n        });\n        int m=queries.size();\n        int idx[m];\n        for(int i=0;i<m;i++){\n            idx[i]=i;\n        }\n        sort(idx,idx+m,[&queries](int a, int b){\n            return queries[a][2]<queries[b][2];\n        });\n        vector<int> sets(n);\n        for(int i=0;i<n;i++){\n            sets[i]=i;\n        }\n        vector<bool> ans(m);\n        int i=0;\n        for(int j=0;j<m;j++){\n            while(i<edgeList.size() && edgeList[i][2]<queries[idx[j]][2]){\n                merge(edgeList[i][0],edgeList[i][1],sets);\n                i++;\n            }\n            ans[idx[j]]=find(queries[idx[j]][0],sets)==find(queries[idx[j]][1],sets);\n        }\n        return ans;\n    }\n```
[]