<doocs>2360.Longest Cycle in a Graph_1.py
def longestCycle( edges: List[int]) -> int:
    n = len(edges)
    vis = [False] * n
    ans = -1
    for i in range(n):
        if vis[i]:
            continue
        curr = i
        cycle = []
        while curr != -1 and not vis[curr]:
            vis[curr] = True
            cycle.append(curr)
            curr = edges[curr]
        if curr == -1:
            continue
        for j, v in enumerate(cycle):
            if v == curr:
                ans = max(ans, len(cycle) - j)
                break
    return ans
def sample_funcname ( var_0 : List [ int ] ) -> int :
    var_4 = len ( var_0 )
    var_6 = [ False ] * var_4
    var_8 = - 1
    for var_10 in range ( var_4 ) :
        if var_6 [ var_10 ] :
            continue
        var_11 = var_10
        var_12 = [ ]
        while var_11 != - 1 and not var_6 [ var_11 ] :
            var_6 [ var_11 ] = True
            var_12.append ( var_11 )
            var_11 = var_0 [ var_11 ]
        if var_11 == - 1 :
            continue
        for var_16 , var_17 in enumerate ( var_12 ) :
            if var_17 == var_11 :
                var_8 = max ( var_8 , len ( var_12 ) - var_16 )
                break
    return var_8
