1489. Find Critical and Pseudo Critical Edges in Minimum Spanning Tree

Practice Find Critical and Pseudo Critical Edges in Minimum Spanning Tree for free on NudgeCode: Hard, Graph pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

You are given a connected, undirected, weighted graph with n nodes labeled 0 to n - 1. edges[i] = [a, b, weight] is edge number i. A minimum spanning tree (MST) is a subset of edges that connects all nodes, has no cycle, and has the smallest possible total weight.

Return [critical, pseudoCritical]: two lists of edge indices, each sorted in ascending order.

Example

n = 5, edges = [[0,1,1],[1,2,1],[2,3,2],[0,3,2],[0,4,3],[3,4,3],[1,4,6]]
->  [[0,1],[2,3,4,5]]

Constraints