def summarize_path(end, previous_nodes):
    """
    Summarize a chain of previous nodes and return path.

    Chain is a dictionary linked list, e.g. {1: None, 2:1, 3:None, 4:2}
    returns [1, 2, 4] for end = 4.
    """
    route = []
    prev = end
    while prev:
        route.insert(0, prev)  # At beginning
        prev = previous_nodes[prev]
    return route