C Union Find with explanation
\n\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* root;\nint** qcopy;\n\nint find(int x) {\n    if(x==root[x])\n    
\n```\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint* root;\nint** qcopy;\n\nint find(int x) {\n    if(x==root[x])\n        return x;\n    else\n        return root[x] = find(root[x]);\n}\n\nint cmp(void const* a, void const* b) {\n    return (*(int**)a)[2] - (*(int**)b)[2];\n}\n\nint cmp2(void const* a, void const* b) {\n    return qcopy[*(int*)a][2] - qcopy[*(int*)b][2];\n}\n\nbool* distanceLimitedPathsExist(int n, int** edgeList, int edgeListSize, int* edgeListColSize, int** queries, int queriesSize, int* queriesColSize, int* returnSize){\n    *returnSize = queriesSize;\n    int i;\n    //init union set\n    root = (int*)malloc(sizeof(int)*n);\n    for (i = 0; i < n; i++)\n        root[i] = i;\n    //init answer array\n    bool* ans = (bool*)malloc(sizeof(bool) * queriesSize);\n\n    int idx[queriesSize];//index of queries\n    for (i = 0; i < queriesSize; ++i)\n        idx[i] = i;\n\n    qcopy = queries;\n    qsort(idx, queriesSize, sizeof(int), cmp2);//sort the index base on the queries limit length\n    qsort(edgeList, edgeListSize, sizeof(int*), cmp); //sort by edge distance\n    \n    int j=0;\n    for (i = 0; i < queriesSize; ++i) {\n        int curr = idx[i];//current queries index in sorted queries\n        int len = queries[curr][2];//limit length\n        \n        //update union set when distance less than limit \n        while(j < edgeListSize && edgeList[j][2] < len){\n            int a = find(edgeList[j][0]);\n            int b = find(edgeList[j][1]);\n            root[b] = a;\n            j++;\n        }\n\n        //check if nodes has same root\n        if (find(queries[curr][0]) == find(queries[curr][1]))\n            ans[curr] = 1;\n        else \n            ans[curr] = 0;\n    }\n\n    return ans;\n}\n```
['C']