


from collections import deque







def SCREAMING_SNAKE_CASE	(			__lowerCAmelCase				)    ->				Union[str, Any]:
  snake_case__						= len(__lowerCAmelCase				)
  snake_case__						= deque()
  snake_case__						= [False for _ in range(__lowerCAmelCase				)]
  snake_case__						= [-1 for _ in range(__lowerCAmelCase				)]
  snake_case__						= index_of[:]

  def strong_connect(__lowerCAmelCase							,   __lowerCAmelCase							,   __lowerCAmelCase				):
    snake_case__						= index  # the number when this node is seen
    snake_case__						= index  # lowest rank node reachable from here
    index += 1
    stack.append(__lowerCAmelCase				)
    snake_case__						= True

    for w in g[v]:
      if index_of[w] == -1:
        snake_case__						= strong_connect(__lowerCAmelCase							,   __lowerCAmelCase							,   __lowerCAmelCase				)
        snake_case__						= (
            lowlink_of[w] if lowlink_of[w] < lowlink_of[v] else lowlink_of[v]
        )
      elif on_stack[w]:
        snake_case__						= (
            lowlink_of[w] if lowlink_of[w] < lowlink_of[v] else lowlink_of[v]
        )

    if lowlink_of[v] == index_of[v]:
      snake_case__						= []
      snake_case__						= stack.pop()
      snake_case__						= False
      component.append(__lowerCAmelCase				)
      while w != v:
        snake_case__						= stack.pop()
        snake_case__						= False
        component.append(__lowerCAmelCase				)
      components.append(__lowerCAmelCase				)
    return index

  snake_case__						= []
  for v in range(__lowerCAmelCase				):
    if index_of[v] == -1:
      strong_connect(__lowerCAmelCase							,   0							,   __lowerCAmelCase				)

  return components







def SCREAMING_SNAKE_CASE	(			__lowerCAmelCase							,   __lowerCAmelCase				)    ->				Optional[int]:
  snake_case__						= [[] for _ in range(__lowerCAmelCase				)]
  for u, v in edges:
    g[u].append(__lowerCAmelCase				)
  return g


if __name__ == "__main__":
   # Test
   lowerCamelCase__							:						Tuple							     =   7
   lowerCamelCase__							:						Optional[Any]							     =   [0, 0, 1, 2, 3, 3, 4, 4, 6]
   lowerCamelCase__							:						Optional[int]							     =   [1, 3, 2, 0, 1, 4, 5, 6, 5]
   lowerCamelCase__							:						int							     =   [(u, v) for u, v in zip(source, target)]
   lowerCamelCase__							:						List[str]							     =   create_graph(n_vertices, edges)

   assert [[5], [6], [4], [3, 2, 1, 0]] == tarjan(g)





import math
class 		__magic_name__						:





     '''simple docstring'''



     def 	SCREAMING_SNAKE_CASE__						(					self:Optional[int]     ,		_a:list[list[float]]     ,		_a:list[int]   ):
       snake_case__						= 0.0
       snake_case__						= 0.0
       for i in range(len(_a   )   ):
         da += math.pow((sample[i] - weights[0][i])     ,		2   )
         da += math.pow((sample[i] - weights[1][i])     ,		2   )
         return 0 if da > da else 1
       return 0







     def 	SCREAMING_SNAKE_CASE__						(					self:Tuple     ,		_a:list[list[int | float]]     ,		_a:list[int]     ,		_a:int     ,		_a:float   ):
       for i in range(len(_a   )   ):
         weights[j][i] += alpha * (sample[i] - weights[j][i])
       return weights







def SCREAMING_SNAKE_CASE	(			)    ->				None:
  # Training Examples ( m, n )
  snake_case__						= [[1, 1, 0, 0], [0, 0, 0, 1], [1, 0, 0, 0], [0, 0, 1, 1]]

  # weight initialization ( n, C )
  snake_case__						= [[0.2, 0.6, 0.5, 0.9], [0.8, 0.4, 0.7, 0.3]]

  # training
  snake_case__						= SelfOrganizingMap()
  snake_case__						= 3
  snake_case__						= 0.5

  for _ in range(__lowerCAmelCase				):
    for j in range(len(__lowerCAmelCase				)				):
      # training sample
      snake_case__						= training_samples[j]

      # Compute the winning vector
      snake_case__						= self_organizing_map.get_winner(__lowerCAmelCase							,   __lowerCAmelCase				)

      # Update the winning vector
      snake_case__						= self_organizing_map.update(__lowerCAmelCase							,   __lowerCAmelCase							,   __lowerCAmelCase							,   __lowerCAmelCase				)

    # classify test sample
  snake_case__						= [0, 0, 0, 1]
  snake_case__						= self_organizing_map.get_winner(__lowerCAmelCase							,   __lowerCAmelCase				)

  # results
  print(F"""Clusters that the test sample belongs to : {winner}"""				)
  print(F"""Weights that have been trained : {weights}"""				)


# running the main() function
if __name__ == "__main__":
   main()

