Given a directed graph having n nodes. For each node, delete all the outgoing edges except the outgoing edge with minimum weight. Apply this deletion operation for every node and then print the final graph remained where each node of the graph has at most one outgoing edge and that too with minimum weight.
Note: Here, graph is stored as Adjacency Matrix for ease.
Input : Adjacency Matrix of input graph : | 1 2 3 4 --------------- 1 | 0 3 2 5 2 | 0 2 4 7 3 | 1 2 0 3 4 | 5 2 1 3 Output : Adjacency Matrix of output graph : | 1 2 3 4 --------------- 1 | 0 0 2 0 2 | 0 2 0 0 3 | 1 0 0 0 4 | 0 0 1 0
For every row of the adjacency matrix of graph keep the minimum element (except zero) and make rest of all zero. Do this for every row of the input matrix. Finally, print the resultant Matrix.
1 0 0 0 0 0 0 5 0 2 0 0 0 0 0 0
Time Complexity: O(n^2)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Product of minimum edge weight between all pairs of a Tree
- Ways to Remove Edges from a Complete Graph to make Odd Edges
- Shortest Path in a weighted Graph where weight of an edge is 1 or 2
- Find weight of MST in a complete graph with edge-weights either 0 or 1
- Path with smallest product of edges with weight >= 1
- Path with smallest product of edges with weight > 0
- Tree, Back, Edge and Cross Edges in DFS of Graph
- Add and Remove Edge in Adjacency List representation of a Graph
- Add and Remove Edge in Adjacency Matrix representation of a Graph
- Minimum edge reversals to make a root
- Find the weight of the minimum spanning tree
- Karp's minimum mean (or average) weight cycle algorithm
- Find minimum weight cycle in an undirected graph
- Minimum number of edges between two vertices of a Graph
- Path with minimum XOR sum of edges in a directed graph
- Dijkstra's shortest path with minimum edges
- Minimum number of edges between two vertices of a graph using DFS
- Minimum steps to reach any of the boundary edges of a matrix | Set 1
- Minimum number of edges that need to be added to form a triangle
- Minimum steps to reach any of the boundary edges of a matrix | Set-2
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.