Skip to content

Instantly share code, notes, and snippets.

@alexandremcosta
Created May 31, 2017 02:22
Show Gist options
  • Save alexandremcosta/07b85c6d5339c42165dba1d45763ccbb to your computer and use it in GitHub Desktop.
Save alexandremcosta/07b85c6d5339c42165dba1d45763ccbb to your computer and use it in GitHub Desktop.
input V, E, d
global visited = []
global distances = [][]
DFS(s)
foreach u in V
visited[u] = false
VISIT(s, s, 0)
VISIT(s, u, partial_distance)
visited[u] = true
distances[s][u] = partial_distance
foreach v in u.adjacents
if not visited[v]
VISIT(s, v, partial_distance + d[u][v])
MAIN
foreach s in V
DFS(s)
return distances
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment