C++ solution using Union find method
\nclass Solution {\npublic:\n    \n    \n    int find(int n,int parent[])\n    {\n        if(parent[n]==-1)\n            return n;\n        return parent[n]=fin
```\nclass Solution {\npublic:\n    \n    \n    int find(int n,int parent[])\n    {\n        if(parent[n]==-1)\n            return n;\n        return parent[n]=find(parent[n],parent);\n    }\n    \n    bool compare(vector<int> &a,vector<int>&b)\n    {\n        return a[2]<b[2];\n    }\n    \n    vector<bool> distanceLimitedPathsExist(int n, vector<vector<int>>& edgeList, vector<vector<int>>& queries) {\n      multimap<int,array<int,3>> mmp;\n        for(int i=0;i<queries.size();i++)\n        {\n            mmp.insert({queries[i][2],{queries[i][0],queries[i][1],i}});\n        }\n        // sort(edgeList.begin(),edgeList.end(),compare);\n        sort(begin(edgeList), end(edgeList), [](vector<int> &a, vector<int> &b) { return a[2] < b[2]; });\n        int parent[n];\n        memset(parent,-1,sizeof(parent));\n        vector<bool> ans(queries.size());\n        \n        int index_edge=0;\n        \n        for(auto &querie:mmp)\n        {\n            while(index_edge<edgeList.size() and querie.first>edgeList[index_edge][2])\n            {\n                int parent1=find(edgeList[index_edge][0],parent);\n                int parent2=find(edgeList[index_edge][1],parent);\n                // parent[edgeList[index_edge][0]]=parent1;\n                // parent[edgeList[index_edge][1]]=parent2;\n                // cout<<parent1<<" "<<parent2<<endl;\n                if(parent1!=parent2)\n                {\n                    parent[parent1]=parent2; \n                }\n                index_edge++;\n                // cout<<index_edge<<" "<<querie.first<<" "<<edgeList[index_edge][2]<<" "<<edgeList.size()<<endl;\n            }\n            if(find(querie.second[0],parent)==find(querie.second[1],parent))\n                ans[querie.second[2]]=true;\n            else\n                ans[querie.second[2]]=false;\n            \n        }\n        for(int i=0;i<edgeList.size();i++)\n            cout<<edgeList[i][2]<<" ";\n        // for(int i=0;i<n;i++)\n        //     cout<<parent[i]<<" ";\n        return ans;\n           \n    }\n};\n```
[]