Skip to content

Instantly share code, notes, and snippets.

View figengungor's full-sized avatar

Figen Güngör figengungor

View GitHub Profile
def adj(g):
"""
Convert a directed graph to an adjaceny matrix.
>>> g = {1: {2: 3, 3: 8, 5: -4}, 2: {4: 1, 5: 7}, 3: {2: 4}, 4: {1: 2, 3: -5}, 5: {4: 6}}
>>> adj(g)
{1: {1: 0, 2: 3, 3: 8, 4: inf, 5: -4}, 2: {1: inf, 2: 0, 3: inf, 4: 1, 5: 7}, 3: {1: inf, 2: 4, 3: 0, 4: inf, 5: inf}, 4: {1: 2, 2: inf, 3: -5, 4: 0, 5: inf}, 5: {1: inf, 2: inf, 3: inf, 4: 6, 5: 0}}
"""
vertices = g.keys()
dist = {}