Single Source Shortest Path (Tree)
Finds the single source shortest path of a tree.
Usage
sssp_tree(graph: Graph, source: int)
Parameters:
graph : Graph
Graph Object
source : int
Source Vertex
Returns:
dict
A dictionary of vertex -> cost
Example
from jellybeans.algos import sssp_treefrom jellybeans.structures import Graphg = Graph()g.add_vertex(0)g.add_vertex(1)g.add_vertex(2)g.add_vertex(3)g.add_bidirected_edge(0, 1, (1, 1))g.add_bidirected_edge(1, 2, (2, 2))g.add_bidirected_edge(1, 3, (3, 3))res = sssp_tree(g, 0)print(res) # {0: 0, 1: 1, 2: 3, 3: 4}