def path(parents,t):
    
    """
    Build path from source to target.
    
    Parameters:
    - - - - -
        parents : array, where each index [i] points to the parent node of
                    node i
        t : node from which to traverse backwards
    """
    path_stack = []
    path_stack.append(t)
    
    while parents[t] != -1:
        path_stack.append(parents[t])
        t = parents[t]

    path = []
    while len(path_stack) != 0:
        path.append(path_stack.pop())
        
    return path