100% Best Solution And Easy Understanble With Comments || MST
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```\n# plss Upvote For Me :(\n\n# Creating Class For MST Algorithm\nclass UnionFind:\n    def __init__ (self, n):\n        self.parents = list(range(n))  # Initialy Every Vertex Is It\'s Own Parent\n        self.weight = 0                # Initialy Weight = 0\n        self.edgeCount = 0             # Initialy edgeCount = 0\n\n    def find(self, x):                 # Find Function TO Find The Parent Of X Recursively\n        if x != self.parents[x]:       # If X is not it\'s Own Parent\n            self.parents[x] = self.find(self.parents[x])    # then Finding It\'s Parent\n        return self.parents[x]         # Returning The Parent Of X\n\n    def union(self, x, y, w):          # Union Function TO Creating MST Algo\n        r1 = self.find(x)              # Finding The X Parent\n        r2 = self.find(y)              # Finding The Y Parent\n\n        if r1 != r2:                   # If the Parents Are Not Same\n            self.parents[r2] = r1      # The create Parent of r2 to r1\n            self.weight += w           # Incresing the Weight\n            self.edgeCount += 1        # Increasing The EsgeCount by 1\n\nclass Solution:\n    def findCriticalAndPseudoCriticalEdges(self, n: int, edges: List[List[int]]) -> List[List[int]]:\n        # Step 1: Sorting the edges List\n        edges = [(w,a,b,i) for i, (a,b,w) in enumerate(edges)]  # As we have to return i (index)\n        edges.sort()\n\n        # Step 2: Finding the First MinWeight In entire edges\n        uf1 = UnionFind(n)\n        for w, a, b, _ in edges:\n            uf1.union(a, b, w)\n\n        minWeight = uf1.weight\n\n        # Step 3: Defining The Critical and Pseudo Critical Edges Empty \n        ce = []\n        pce = []\n        m = len(edges)\n\n\n        # step 4: Now Including And Excludeing the edges to find Critical and PsuedoCritical edges\n        for i in range(m):\n            uf2 = UnionFind(n)              # Creting New uf2 UnionFind Class\n            for j in range(m):              # for every edge\n                if i == j:\n                    continue\n                w,a,b,_ = edges[j]    \n                uf2.union(a,b,w)            # Unioning the x, y\n            \n            # if curr weight is greather or we didn\'t draw the proper graph\n            if uf2.weight > minWeight or uf2.edgeCount < n-1:\n                ce.append(edges[i][3])     # It is a Critical Edge\n\n\n            else:\n                # Forcefully adding the edge i and again doing MST Algo\n                uf3 = UnionFind(n)               # creating new object Class\n                w,a,b,_ = edges[i]               # taking the i edges\n                uf3.union(a,b,w)                 # unioning the first i edge\n                for j in range(m):\n                    w,a,b,_ = edges[j]           # Uninoning the edges acordingly\n                    uf3.union(a,b,w)\n                \n                if uf3.weight == minWeight:      # If curr weight == min wight\n                    pce.append(edges[i][3])      # it is a PseudoCritical Edge\n\n        return ce, pce    # Now Returning The Critical Edge And PseudoCretical Edge\n```
['Python3']