C++ || Union-Find
Sort all edges as well as queries in increasing order. To answer a query i.e. (qv1,qv2,weight) we connect all those edges whose weights are strictly less than \
Sort all edges as well as queries in increasing order. To answer a query i.e. (qv1,qv2,weight) we connect all those edges whose weights are strictly less than \'weight\'. After connecting those edges we check if the query nodes are connected or not which will be true only if edge weights smaller than \'weight\' were involved else it would be false as it requires extra edges having edge weights greater than \'weight\'.\n\n```\nclass Solution {\npublic:\n    vector<int>parent,rank;\n    \n    void initialize(int n){\n        for(int i=0;i<n;i++){\n            parent[i]=i;\n            rank[i]=0;\n        }\n    }\n    \n    int findPar(int v){\n        if(v==parent[v]) return v;\n        return parent[v]=findPar(parent[v]);\n    }\n    \n    vector<bool> distanceLimitedPathsExist(int n, vector<vector<int>>& edgeList, vector<vector<int>>& queries) {\n        int s=edgeList.size();\n        int m=queries.size();\n        parent.resize(n);\n        rank.resize(n);\n        initialize(n);\n        \n        vector<vector<int>>edges,q;\n        for(int i=0;i<s;i++){\n            vector<int>t;\n            t.push_back(edgeList[i][2]); t.push_back(i);\n            edges.push_back(t);\n        }\n        for(int i=0;i<m;i++){\n            vector<int>t;\n            t.push_back(queries[i][2]); t.push_back(i);\n            q.push_back(t);\n        }\n        \n        sort(edges.begin(),edges.end());\n        sort(q.begin(),q.end());\n        \n        vector<bool>ans(m);\n        int start=0;\n        \n        for(int i=0;i<m;i++){\n            int weight=q[i][0];\n            int qv1=queries[q[i][1]][0];\n            int qv2=queries[q[i][1]][1];\n            for(int j=start;j<s;j++){\n                if(edges[j][0]<weight){\n                    int v1=edgeList[edges[j][1]][0];\n                    int v2=edgeList[edges[j][1]][1];\n                    int u=findPar(v1);\n                    int v=findPar(v2);\n                    if(u!=v){\n                        //union\n                        if(rank[u]<rank[v])\n                            parent[u]=v;\n                        else if(rank[v]<rank[u])\n                            parent[v]=u;\n                        else\n                            parent[v]=u,rank[u]++;\n                    }\n                    start++;\n                    \n                }\n                else\n                    break;\n                \n            }\n            if(findPar(qv1)==findPar(qv2))\n                ans[q[i][1]]=true;\n            else\n                ans[q[i][1]]=false;\n        }\n        return ans;\n    }\n};\n```
['C']