def printpath(P, u, w):
    """
    Given modified path cost matrix (see floydwarshall) return shortest path
    from i to j.
    """
    path = [u]
    while P[u][w][1] != -1:
        path.append(P[u][w][1])
        u = P[u][w][1]
    return path