c++ solution using dsu
\nclass union_find\n{\n    private:\n    vector<int>parent;\n    vector<int>rank;\n    public:\n    union_find(int n)\n    {\n        parent=vector<int>(n,0);\n
```\nclass union_find\n{\n    private:\n    vector<int>parent;\n    vector<int>rank;\n    public:\n    union_find(int n)\n    {\n        parent=vector<int>(n,0);\n        rank=vector<int>(n,1);\n        iota(parent.begin(),parent.end(),0);\n    }\n    int find(int x)\n    {\n        if(x==parent[x])\n        {\n            return x;\n        }\n        return parent[x]=find(parent[x]);\n    }\n    void merge(int x,int y)\n    {\n        if(rank[x]>rank[y])\n        {\n            parent[y]=x;\n            rank[x]+=rank[y];\n        }\n        else\n        {\n             parent[x]=y;\n             rank[y]+=rank[x];\n        }\n    }\n    bool is_connected(int x,int y)\n    {\n        return find(x)==find(y);\n    }\n};\n\nclass Solution {\npublic:\n    vector<bool> distanceLimitedPathsExist(int n, vector<vector<int>>&nums, vector<vector<int>>& q) \n    {    \n        union_find dsu(n);\n        sort(nums.begin(),nums.end(),[&](auto &a,auto &b)\n             {return a[2]<b[2];});\n        for(int i=0;i<q.size();i++)\n        {\n            q[i].push_back(i);\n        }\n        sort(q.begin(),q.end(),[&](auto &a,auto &b)\n             {return a[2]<b[2];});\n        int i=0;\n        int X=nums.size();\n        vector<bool>ans(q.size());\n        for(auto it:q)\n        {\n            while(i<X&&nums[i][2]<it[2])\n            {\n                int p1=dsu.find(nums[i][0]);\n                int p2=dsu.find(nums[i][1]);\n                if(p1!=p2)\n                {\n                   dsu.merge(p1,p2);\n                }\n                i++;\n            }\n            ans[it[3]]=dsu.is_connected(it[0],it[1]);\n        }\n        return ans;\n    }\n};\n```
['Union Find', 'C', 'C++']