Skip to content

Instantly share code, notes, and snippets.

@rgrig
Created March 11, 2011 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgrig/865643 to your computer and use it in GitHub Desktop.
Save rgrig/865643 to your computer and use it in GitHub Desktop.
cache = dict() # cache[x] is a map from weights to paths s->x
s = 0 # source
def find(t):
if t in cache: return cache[t]
if t == s:
return dict([(0,[s])])
r = dict()
for (x, w) in pred(t):
for (ww, path) in find(x):
r[w+ww] = cons(t, path)
return r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment