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)
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- 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
- 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
- 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
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.