Given a weighted undirected connected graph with n vertices numbered from 0 to n - 1, and an array edges where edges[i] = [ai, bi, weighti] represents a bidirectional and weighted edge between nodes ai and bi. A minimum spanning tree (MST) is a subset of the graph’s edges that connects all vertices without cycles and with the minimum possible total edge weight.
Find all the critical and pseudo-critical edges in the given graph’s minimum spanning tree (MST). An MST edge whose deletion from the graph would cause the MST weight to increase is called a critical edge. On the other hand, a pseudo-critical edge is that which can appear in some MSTs but not all.
Note that you can return the indices of the edges in any order.
classSolution { intfind(vector<int>& g, int n){ return g[n] == n ? n : g[n] = find(g,g[n]); } voiduni(vector<int>& g, int u, int v){ int pu = find(g,u), pv = find(g,v); g[pu] = g[pv] = min(pu, pv); } intmstCost(int n, vector<vector<int>>& edges, int blockEdge, int reqEdge){ int cost = 0; vector<int> g(n); for(int i = 0; i < n; i++) g[i] = i;