def DFS_TS_subroutine(adjacency_list, explored, current_label, labels, s):
    """
    Non-recursive subroutine called by DFS_TS.
    Args:
    adjacency_list - the graph in its adjacency list representation.
    explored - whether each node has been explored.
    current_label - the next label to be assigned.
    labels - the list holding the labels of each node.
    s - stack to assist this subroutine.
    """
    # mark node i as explored
    i = s[-1]
    explored[i] = 1
    exhausted = True
    for j in adjacency_list[i]:
        # stack each neighbor that has not yet been explored
        if not bool(explored[j]):
            exhausted = False
            s.append(j)
    if exhausted:
        s.pop()
        # assign label and decrement it
        if not labels[i] >= 0:
            labels[i] = current_label
            current_label -= 1
    return current_label