comefrom: <doocs>2360.Longest Cycle in a Graph_1.py
code: 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
masked: def sample_funcname ( var_0 : List [ int ] ) -> int :
      var_1 = len ( var_0 )
      var_2 = [ False ] * var_1
      var_3 = - 1
      for var_4 in range ( var_1 ) :
          if var_2 [ var_4 ] :
              continue
          var_5 = var_4
          var_6 = [ ]
          while var_5 != - 1 and not var_2 [ var_5 ] :
              var_2 [ var_5 ] = True
              var_6.append ( var_5 )
              var_5 = var_0 [ var_5 ]
          if var_5 == - 1 :
              continue
          for var_7 , var_8 in enumerate ( var_6 ) :
              if var_8 == var_5 :
                  var_3 = max ( var_3 , len ( var_6 ) - var_7 )
                  break
      return var_3
  