There are n nodes and m bridges in between these nodes. Print the possible path through each node using each edges (if possible), traveling through each edges only once.
Input : [[0, 1, 0, 0, 1], [1, 0, 1, 1, 0], [0, 1, 0, 1, 0], [0, 1, 1, 0, 0], [1, 0, 0, 0, 0]] Output : 5 -> 1 -> 2 -> 4 -> 3 -> 2 Input : [[0, 1, 0, 1, 1], [1, 0, 1, 0, 1], [0, 1, 0, 1, 1], [1, 1, 1, 0, 0], [1, 0, 1, 0, 0]] Output : "No Solution"
It is one of the famous problems in Graph Theory and known as problem of “Seven Bridges of Königsberg”. This problem was solved by famous mathematician Leonhard Euler in 1735. This problem is also considered as the beginning of Graph Theory.
The problem back then was that: There was 7 bridges connecting 4 lands around the city of Königsberg in Prussia. Was there any way to start from any of the land and go trough each of the bridges once and only once? Please see these wikipedia images for more clarity.
Euler first introduced graph theory to solve this problem. He considered each of the lands as a node of a graph and each bridge in between as an edge in between. Now he calculated if there is any Eulerian Path in that graph. If there is an Eulerian path then there is a solution otherwise not.
Problem here, is a generalized version of the problem in 1735.
Below is the implementation :
2-0 0-1 1-2 2-3 1-0 0-2 2-3 3-1 1-0 0-2
- Find maximum number of edge disjoint paths between two vertices
- Maximize number of nodes which are not part of any edge in a Graph
- Number of Unicolored Paths between two nodes
- Check if given path between two nodes of a graph represents a shortest paths
- Bridges in a graph
- Edge Coloring of a Graph
- Minimum edge reversals to make a root
- Program to Calculate the Edge Cover of a Graph
- Check if removing a given edge disconnects a graph
- Delete Edge to minimize subtree sum difference
- Product of minimum edge weight between all pairs of a Tree
- Remove all outgoing edges except edge with minimum weight
- Tree, Back, Edge and Cross Edges in DFS of Graph
- Shortest Path in a weighted Graph where weight of an edge is 1 or 2
- Maximum Possible Edge Disjoint Spanning Tree From a Complete Graph
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.