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
- Tree, Back, Edge and Cross Edges in DFS of Graph
- Path with smallest product of edges with weight >= 1
- Path with smallest product of edges with weight > 0
- Add and Remove Edge in Adjacency List representation of a Graph
- Add and Remove Edge in Adjacency Matrix representation of a Graph
- Find sum of all elements in a matrix except the elements in row and/or column of given cell?
- Minimum edge reversals to make a root
- Minimum Cost using Dijkstra by reducing cost of an Edge
- Count number of times each Edge appears in all possible paths of a given Tree
- Find minimum weight cycle in an undirected graph
- Find the weight of the minimum spanning tree
- Karp's minimum mean (or average) weight cycle algorithm
- Minimum edges to reverse to make path from a source to a destination
- Minimum edges required to add to make Euler Circuit
- Minimum number of edges between two vertices of a Graph
- 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 firstname.lastname@example.org. 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.