C# Solution | Union Find | Sorting
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\npublic class Solution {\n    public bool[] DistanceLimitedPathsExist(int n, int[][] edgeList, int[][] queries) {\n        int edgesCount = edgeList.Length, queriesCount = queries.Length;\n        DSU dsu = new DSU(n);\n\n        for (int i = 0; i < queriesCount; i++) \n            queries[i] = new int[]{queries[i][0], queries[i][1], queries[i][2], i}; \n\n        Array.Sort(queries, (a, b) => a[2] - b[2]);\n        Array.Sort(edgeList, (a, b) => a[2] - b[2]);\n        bool[] res = new bool[queriesCount];\n\n        for (int i = 0, j = 0; i < queriesCount; i++) {\n            var query = queries[i];\n\n            while (j < edgesCount && edgeList[j][2] < queries[i][2])\n                dsu.union(edgeList[j][0], edgeList[j++][1]);\n\n            res[queries[i][3]] = dsu.find(queries[i][0]) == dsu.find(queries[i][1]);\n        }\n\n        return res;\n    }\n\n    class DSU {\n        public int[] parent;\n\n        public DSU(int n) {\n            parent = new int[n];\n\n            for (int i = 0; i < n; i++) parent[i] = i;\n        }\n\n        public int find(int x) {\n            if (parent[x] != x) parent[x] = find(parent[x]);\n            return parent[x];\n        }\n\n        public void union(int x, int y) {\n            parent[find(x)] = parent[find(y)];\n        }\n    }\n}\n```
['Array', 'Union Find', 'Graph', 'Sorting', 'C#']