



"""simple docstring"""







from manim import *







class       UpperCamelCase__   (	lowercase_  ):




      """simple docstring"""




      def      SCREAMING_SNAKE_CASE__ (      self				:      List[Any]       ):
        lowerCAmelCase_   :				Optional[int]								= Rectangle(height=0.5    ,			width=0.5       )
        lowerCAmelCase_   :				str								= Rectangle(height=0.25    ,			width=0.25       )
        lowerCAmelCase_   :				Optional[int]								= Rectangle(height=0.46    ,			width=0.46       ).set_stroke(width=0       )

        lowerCAmelCase_   :				List[Any]								= [mem.copy() for i in range(6       )]
        lowerCAmelCase_   :				Optional[Any]								= [mem.copy() for i in range(6       )]
        lowerCAmelCase_   :				Tuple								= VGroup(*SCREAMING_SNAKE_CASE_       ).arrange(SCREAMING_SNAKE_CASE_    ,			buff=0       )
        lowerCAmelCase_   :				Union[str, Any]								= VGroup(*SCREAMING_SNAKE_CASE_       ).arrange(SCREAMING_SNAKE_CASE_    ,			buff=0       )
        lowerCAmelCase_   :				Union[str, Any]								= VGroup(SCREAMING_SNAKE_CASE_    ,			SCREAMING_SNAKE_CASE_       ).arrange(SCREAMING_SNAKE_CASE_    ,			buff=0       )
        lowerCAmelCase_   :				Union[str, Any]								= Text('CPU'    ,			font_size=2_4       )
        lowerCAmelCase_   :				Union[str, Any]								= Group(SCREAMING_SNAKE_CASE_    ,			SCREAMING_SNAKE_CASE_       ).arrange(SCREAMING_SNAKE_CASE_    ,			buff=0.5    ,			aligned_edge=SCREAMING_SNAKE_CASE_       )
        cpu.move_to([-2.5, -0.5, 0]       )
        self.add(SCREAMING_SNAKE_CASE_       )

        lowerCAmelCase_   :				Dict								= [mem.copy() for i in range(4       )]
        lowerCAmelCase_   :				Optional[Any]								= VGroup(*SCREAMING_SNAKE_CASE_       ).arrange(SCREAMING_SNAKE_CASE_    ,			buff=0       )
        lowerCAmelCase_   :				Union[str, Any]								= Text('GPU'    ,			font_size=2_4       )
        lowerCAmelCase_   :				List[str]								= Group(SCREAMING_SNAKE_CASE_    ,			SCREAMING_SNAKE_CASE_       ).arrange(SCREAMING_SNAKE_CASE_    ,			buff=0.5    ,			aligned_edge=SCREAMING_SNAKE_CASE_       )
        gpu.move_to([-1, -1, 0]       )
        self.add(SCREAMING_SNAKE_CASE_       )

        lowerCAmelCase_   :				List[str]								= [mem.copy() for i in range(6       )]
        lowerCAmelCase_   :				Optional[Any]								= VGroup(*SCREAMING_SNAKE_CASE_       ).arrange(SCREAMING_SNAKE_CASE_    ,			buff=0       )

        lowerCAmelCase_   :				int								= Text('Model'    ,			font_size=2_4       )
        lowerCAmelCase_   :				Any								= Group(SCREAMING_SNAKE_CASE_    ,			SCREAMING_SNAKE_CASE_       ).arrange(SCREAMING_SNAKE_CASE_    ,			buff=0.5    ,			aligned_edge=SCREAMING_SNAKE_CASE_       )
        model.move_to([3, -1.0, 0]       )
        self.add(SCREAMING_SNAKE_CASE_       )

        lowerCAmelCase_   :				int								= []
        lowerCAmelCase_   :				Tuple								= []
        lowerCAmelCase_   :				Union[str, Any]								= []

        for i, rect in enumerate(SCREAMING_SNAKE_CASE_       ):
          rect.set_stroke(SCREAMING_SNAKE_CASE_       )

          lowerCAmelCase_   :				Tuple								= Rectangle(height=0.46 / 4    ,			width=0.46 / 3       ).set_stroke(width=0.0       ).set_fill(SCREAMING_SNAKE_CASE_    ,			opacity=0.7       )

          if i == 0:
            cpu_target.next_to(cpu_left_col_base[0].get_corner(DOWN + LEFT       )    ,			buff=0.02    ,			direction=SCREAMING_SNAKE_CASE_       )
            cpu_target.set_x(cpu_target.get_x() + 0.1       )
          elif i == 3:
            cpu_target.next_to(model_cpu_arr[0]    ,			direction=SCREAMING_SNAKE_CASE_    ,			buff=0.0       )
          else:
            cpu_target.next_to(model_cpu_arr[i - 1]    ,			direction=SCREAMING_SNAKE_CASE_    ,			buff=0.0       )
          self.add(SCREAMING_SNAKE_CASE_       )
          model_cpu_arr.append(SCREAMING_SNAKE_CASE_       )

        self.add(*SCREAMING_SNAKE_CASE_    ,			*SCREAMING_SNAKE_CASE_    ,			*SCREAMING_SNAKE_CASE_       )

        lowerCAmelCase_   :				Optional[Any]								= [mem.copy() for i in range(6       )]
        lowerCAmelCase_   :				Union[str, Any]								= VGroup(*SCREAMING_SNAKE_CASE_       ).arrange(SCREAMING_SNAKE_CASE_    ,			buff=0       )

        lowerCAmelCase_   :				Any								= Text('Loaded Checkpoint'    ,			font_size=2_4       )
        lowerCAmelCase_   :				Optional[Any]								= Group(SCREAMING_SNAKE_CASE_    ,			SCREAMING_SNAKE_CASE_       ).arrange(SCREAMING_SNAKE_CASE_    ,			buff=0.5    ,			aligned_edge=SCREAMING_SNAKE_CASE_       )
        checkpoint.move_to([3, 0.5, 0]       )

        self.add(SCREAMING_SNAKE_CASE_       )

        lowerCAmelCase_   :				Any								= []
        lowerCAmelCase_   :				Union[str, Any]								= []

        for i, rect in enumerate(SCREAMING_SNAKE_CASE_       ):
          lowerCAmelCase_   :				str								= fill.copy().set_fill(SCREAMING_SNAKE_CASE_    ,			opacity=0.7       )
          target.move_to(SCREAMING_SNAKE_CASE_       )
          ckpt_arr.append(SCREAMING_SNAKE_CASE_       )

          lowerCAmelCase_   :				str								= target.copy()
          if i < 5:
            cpu_target.move_to(cpu_left_col_base[i + 1]       )
          else:
            cpu_target.move_to(cpu_right_col_base[i - 5]       )
          ckpt_cpu_arr.append(SCREAMING_SNAKE_CASE_       )
        self.add(*SCREAMING_SNAKE_CASE_    ,			*SCREAMING_SNAKE_CASE_       )

        lowerCAmelCase_   :				Union[str, Any]								= Square(side_length=2.2       )
        key.move_to([-5, 2, 0]       )

        lowerCAmelCase_   :				List[Any]								= MarkupText(
            F"<b>Key:</b>\n\n<span fgcolor='{YELLOW}'>●</span> Empty Model"    ,			font_size=1_8    ,			)

        key_text.move_to([-5, 2.4, 0]       )

        self.add(SCREAMING_SNAKE_CASE_    ,			SCREAMING_SNAKE_CASE_       )

        lowerCAmelCase_   :				Optional[int]								= MarkupText(
            F"<span fgcolor='{BLUE}'>●</span> Checkpoint"    ,			font_size=1_8    ,			)

        blue_text.next_to(SCREAMING_SNAKE_CASE_    ,			DOWN * 2.4    ,			aligned_edge=key_text.get_left()       )
        self.add(SCREAMING_SNAKE_CASE_       )

        lowerCAmelCase_   :				Union[str, Any]								= MarkupText(
            F"Based on the passed in configuration, weights are stored in\na variety of np.memmaps on disk or to a particular device."    ,			font_size=2_4    ,			)
        step_a.move_to([2, 2, 0]       )

        lowerCAmelCase_   :				List[Any]								= [meta_mem.copy() for i in range(6       )]
        lowerCAmelCase_   :				Optional[int]								= [meta_mem.copy() for i in range(6       )]
        lowerCAmelCase_   :				Optional[Any]								= VGroup(*SCREAMING_SNAKE_CASE_       ).arrange(SCREAMING_SNAKE_CASE_    ,			buff=0       )
        lowerCAmelCase_   :				List[str]								= VGroup(*SCREAMING_SNAKE_CASE_       ).arrange(SCREAMING_SNAKE_CASE_    ,			buff=0       )
        lowerCAmelCase_   :				Optional[int]								= VGroup(SCREAMING_SNAKE_CASE_    ,			SCREAMING_SNAKE_CASE_       ).arrange(SCREAMING_SNAKE_CASE_    ,			buff=0       )
        lowerCAmelCase_   :				Optional[int]								= Text('Disk'    ,			font_size=2_4       )
        lowerCAmelCase_   :				Union[str, Any]								= Group(SCREAMING_SNAKE_CASE_    ,			SCREAMING_SNAKE_CASE_       ).arrange(SCREAMING_SNAKE_CASE_    ,			buff=0.5    ,			aligned_edge=SCREAMING_SNAKE_CASE_       )
        disk.move_to([-4.0, -1.25, 0]       )
        self.play(Write(SCREAMING_SNAKE_CASE_    ,			run_time=3       )    ,			Write(SCREAMING_SNAKE_CASE_    ,			run_time=1       )    ,			Create(SCREAMING_SNAKE_CASE_    ,			run_time=1       )       )

        lowerCAmelCase_   :				Optional[int]								= []
        for i, rect in enumerate(SCREAMING_SNAKE_CASE_       ):
          lowerCAmelCase_   :				Dict								= rect.copy()
          target.generate_target()
          target.target.move_to(disk_left_col_base[i]       ).scale(0.5       )
          animations.append(MoveToTarget(SCREAMING_SNAKE_CASE_    ,			run_time=1.5       )       )
        self.play(*SCREAMING_SNAKE_CASE_       )

        self.play(FadeOut(SCREAMING_SNAKE_CASE_       )       )

        lowerCAmelCase_   :				List[str]								= MarkupText(F"Then, the checkpoint is removed from memory\nthrough garbage collection."    ,			font_size=2_4       )
        step_a.move_to([2, 2, 0]       )

        self.play(Write(SCREAMING_SNAKE_CASE_    ,			run_time=3       )       )

        self.play(
            FadeOut(SCREAMING_SNAKE_CASE_    ,			SCREAMING_SNAKE_CASE_    ,			*SCREAMING_SNAKE_CASE_    ,			*SCREAMING_SNAKE_CASE_       )    ,			)

        self.wait()










"""simple docstring"""







def 				UpperCamelCase_    (    lowerCAmelCase__      :				Optional[Any]						)						->   Optional[int]:

  """simple docstring"""




  lowerCAmelCase_   :				Tuple								= [0] * len(lowerCAmelCase__						)
  lowerCAmelCase_   :				List[str]								= []
  lowerCAmelCase_   :				Tuple								= [1] * len(lowerCAmelCase__						)

  for values in graph.values():
    for i in values:
      indegree[i] += 1

  for i in range(len(lowerCAmelCase__						)						):
    if indegree[i] == 0:
      queue.append(lowerCAmelCase__						)

  while queue:
    lowerCAmelCase_   :				Union[str, Any]								= queue.pop(0						)
    for x in graph[vertex]:
      indegree[x] -= 1

      if long_dist[vertex] + 1 > long_dist[x]:
        lowerCAmelCase_   :				Any								= long_dist[vertex] + 1

      if indegree[x] == 0:
        queue.append(lowerCAmelCase__						)

  print(max(lowerCAmelCase__						)						)


# Adjacency list of Graph
lowercase__		:				Any          =	{0: [2, 3, 4], 1: [2, 7], 2: [5], 3: [5, 7], 4: [7], 5: [6], 6: [7], 7: []}
longest_distance(graph)





