def connect(i, timestep):
    dfn[i] = low[i] = timestep[0]
    timestep[0] += 1
    stack.append(i)
    onstack[i] = True
    for (j, head) in enumerate(sequence):
        if (head != i):
            continue
        if (dfn[j] == (- 1)):
            (yield from connect(j, timestep))
            low[i] = min(low[i], low[j])
        elif onstack[j]:
            low[i] = min(low[i], dfn[j])
    if (low[i] == dfn[i]):
        cycle = [stack.pop()]
        while (cycle[(- 1)] != i):
            onstack[cycle[(- 1)]] = False
            cycle.append(stack.pop())
        onstack[i] = False
        if (len(cycle) > 1):
            (yield cycle)
def connect(i, timestep):
    dfn[i] = low[i] = timestep[0]
    timestep[0] += 1
    stack.append(i)
    onstack[i] = True
    for (j, head) in enumerate(sequence):
        if (head != i):
            continue
        if (dfn[j] == (- 1)):
            (yield from connect(j, timestep))
            low[i] = min(low[i], low[j])
        elif onstack[j]:
            low[i] = min(low[i], dfn[j])
    if (low[i] == dfn[i]):
        cycle = [stack.pop()]
        while (cycle[(- 1)] != i):
            onstack[cycle[(- 1)]] = False
            cycle.append(stack.pop())
        onstack[i] = False
        if (len(cycle) > 1):
            (yield cycle)