def path_to(node_from, src, target):
    """
    Given a dictionary that results from a search, reproduce path from original src
    to target. Have to follow the node_from in reverse order, which is why the
    nodes discovered are all inserted at index position 0 in the path.
    Performance is O(N) since a path could involve all nodes, in the worst case.
    """
    if not target in node_from:
        raise ValueError('{} is unreachable from {}'.format(target, src))
    path = []
    v = target
    while v != src:
        path.append(v)
        v = node_from[v]
    # last one to push is the source, which makes it
    # the first one to be retrieved
    path.append(src)
    path.reverse()
    return path