This Python script uses the Bellman-Ford algorithm to find the shortest path in a weighted directed graph. It features an interactive menu and colorful output.
| Image 1 | Image 2 |
|---|---|
![]() |
![]() |
- Interactive Menu: Choose options to find the shortest path or exit.
- Graph Visualization: Display shortest paths with vertices and distances.
- Exception Handling: Informative error messages for invalid inputs and negative weight cycles.
- Colorful Output: Attractive console output with colorful text.
- Run with
python filename.py. - Choose option 1 to find the shortest path.
- Input the following details:
- Number of vertices in the graph.
- Number of edges in the graph.
- For each edge, enter source, destination, and weight (separated by spaces).
- Enter the source and destination vertices.
- View the shortest path and distance or handle errors.
- Represents a weighted directed graph.
add_edge(u, v, w): Adds an edge with sourceu, destinationv, and weightw.bellman_ford(src): Finds shortest paths from the source vertex.
find_shortest_path(): Creates a graph, finds paths, and prints results.print_menu(): Displays a colorful menu.main(): Main driver for user interaction.
- Option 1: Find the shortest path.
- Option 2: Exit the program.
Feel free to contribute and improve this code! ๐ค

