Optimizing Disjoint Set Data Structure For Minimum Cost Queries
TC: O(n*4alpha) optimized using Disjoint Set data structure & bitwise AND op to find min cost of edges & common parents.
Problem TC: O(n*4alpha) class Solution { public int[] minimumCost(int n, int[][] edges, int[][] query) { Disjoint d = new Disjoint(n); Map<Integer,Integer> map = new HashMap<>(); for(int edge[] :edges){ int u = edge[0]; int v = edge[1]; int w = edge[2]; //if parents are not same then union them (will create common parent for both u and v) if(d.findParent(u) != d.findParent(v)){ //since u and v will be unioned there values will also be updated as below //distance value of t...