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)
- 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
- Tree, Back, Edge and Cross Edges in DFS of 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
- Minimum number of edges between two vertices of a graph using DFS
- Dijkstra's shortest path with minimum edges
- Minimum steps to reach any of the boundary edges of a matrix | Set-2
- Minimum steps to reach any of the boundary edges of a matrix | Set 1
- Minimum edges required to add to make Euler Circuit
- Minimum number of edges that need to be added to form a triangle
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.