


1) A weighted graph refers to one where weights are assigned to each edge, undirected graphs are those where edges are bi-directional and have no arrows.
2) If no edge exists return -1.
3) Return the edges in the sorted order of their indices.
N = 4, M = 4
[[0, 1, 1],
[0, 2, 1],
[0, 3, 2],
[2, 3, 2]]

The critical connections are the 0th connection and the 1st connection because removing the causes the MST weight to increase.
The 2nd and 3rd connections are pseudo-critical because any one of the edges can be taken to make MST.
The first line of input contains an integer T denoting the number of test cases.
The first line of each test case contains exactly two space-separated integers, ‘N’, which denotes the number of nodes, and ‘M’, which denotes the number of edges.
The next 'M' lines contain exactly three space-separated integers representing 'NODE1', 'NODE2', and 'EDGE WEIGHT'.
For each test case, print single lines containing two space-separated integers for each pseudo-critical connections and the critical connection. If any of this doesn’t exist return -1.
The output of each test case will be printed in a separate line.
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 500
1 <= M <= 1000
0 <= EDGES[i][j] <= 10^5
Where ‘T’ is the total number of test cases, 'N' is the number of nodes and 'M' is the number of edges, ‘EDGES’ is the given matrix and ‘EDGES’[i][j] is the value of pairs (i,j).
Time limit: 1 sec
The main idea is to use a DSU data structure, to find connected components. A DSU data structure can be used to maintain knowledge of the connected components of a graph, and query for them quickly. In particular, we would like to support two operations:
find(node x), which outputs a unique id so that two nodes have the same id if and only if they are in the same connected component, and:
union(node x, node y), which draws an edge (x, y) in the graph, connecting the components with id find(x) and find(y) together.
Using DSU we need to find MST, using the Kruskal algorithm.
Below are the steps for finding MST using Kruskal’s algorithm