New update is available. Click here to update.

Last Updated: 17 Jan, 2021

Difficulty: Moderate

```
The MST (Minimum Spanning Tree) for the above graph is:
```

```
The first line of input contains an integer 'T' representing the number of the test case. Then the test cases are as follows.
The first line of each test case argument given is an integer ‘N’ representing the number of nodes in the graph.
The second line of each test case contains a given integer ‘M’ representing the number of edges.
The next ‘M’ lines in each test case contain a matrix ‘E’ of size M x 2 which represents the ‘M’ edges such that there is an edge directed from node E[i][0] to node E[i][1].
```

```
For each test case, print the minimum spanning tree in the form of edges and their weights which are included in the MST.
```

```
You do not need to print anything; It has already been taken care of.
```

```
1 ≤ T ≤ 5
2 <= N <= 100
1 <= M <= min(1000, N(N - 1) / 2)
1 <= E[i][0], E[i][1] <= N
Time Limit: 1 sec
```

SIMILAR PROBLEMS

Ninja and the experiment

Posted: 5 Sep, 2022

Difficulty: Moderate

COUNT ISLANDS

Posted: 14 Sep, 2022

Difficulty: Moderate

Distance to a Cycle in Undirected Graph

Posted: 7 Nov, 2022

Difficulty: Moderate

Search In A Sorted 2D Matrix

Posted: 23 Nov, 2022

Difficulty: Moderate

Spiral Matrix

Posted: 24 Nov, 2022

Difficulty: Easy

Popular Interview Problems: