




def 				_A  (		lowerCAmelCase_	:   Optional[Any]     ):
     """simple docstring"""

     lowerCAmelCase__            =					[0] * len(lowerCAmelCase_     )
     lowerCAmelCase__            =					[]
     lowerCAmelCase__            =					[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__            =					queue.pop(0     )
          for x in graph[vertex]:
               indegree[x] -= 1

               if long_dist[vertex] + 1 > long_dist[x]:
                    lowerCAmelCase__            =					long_dist[vertex] + 1

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

     print(max(lowerCAmelCase_     )     )


# Adjacency list of Graph
UpperCamelCase								=	{0: [2, 3, 4], 1: [2, 7], 2: [5], 3: [5, 7], 4: [7], 5: [6], 6: [7], 7: []}






longest_distance(graph)







'''simple docstring'''




from __future__ import annotations

from statistics import mean



def 		__A		(  lowerCamelCase_			,			lowerCamelCase_			,			lowerCamelCase_	):


		"""simple docstring"""



		SCREAMING_SNAKE_CASE :				List[Any]		=			[0] * no_of_processes
		SCREAMING_SNAKE_CASE :				int		=			[0] * no_of_processes

		# Initialize remaining_time to waiting_time.

		for i in range(lowerCamelCase_	):
				SCREAMING_SNAKE_CASE :				Optional[int]		=			burst_time[i]
		SCREAMING_SNAKE_CASE :				list[int]		=			[]

		SCREAMING_SNAKE_CASE :				List[str]		=			0
		SCREAMING_SNAKE_CASE :				List[Any]		=			0

		# When processes are not completed,
		# A process whose arrival time has passed \
		# and has remaining execution time is put into the ready_process.
		# The shortest process in the ready_process, target_process is executed.

		while completed != no_of_processes:
				SCREAMING_SNAKE_CASE :				Optional[int]		=			[]
				SCREAMING_SNAKE_CASE :				Any		=			-1

				for i in range(lowerCamelCase_	):
						if (arrival_time[i] <= total_time) and (remaining_time[i] > 0):
								ready_process.append(lowerCamelCase_	)

				if len(lowerCamelCase_	) > 0:
						SCREAMING_SNAKE_CASE :				Union[str, Any]		=			ready_process[0]
						for i in ready_process:
								if remaining_time[i] < remaining_time[target_process]:
										SCREAMING_SNAKE_CASE :				Any		=			i
						total_time += burst_time[target_process]
						completed += 1
						SCREAMING_SNAKE_CASE :				Any		=			0
						SCREAMING_SNAKE_CASE :				Optional[int]		=			(
						    total_time - arrival_time[target_process] - burst_time[target_process]
						)
				else:
						total_time += 1

		return waiting_time



def 		__A		(  lowerCamelCase_			,			lowerCamelCase_			,			lowerCamelCase_	):


		"""simple docstring"""



		SCREAMING_SNAKE_CASE :				Any		=			[0] * no_of_processes
		for i in range(lowerCamelCase_	):
				SCREAMING_SNAKE_CASE :				Union[str, Any]		=			burst_time[i] + waiting_time[i]
		return turn_around_time


if __name__ == "__main__":
							print("""[TEST CASE 01]""")

							__UpperCAmelCase            =       4
							__UpperCAmelCase            =       [2, 5, 3, 7]
							__UpperCAmelCase            =       [0, 0, 0, 0]
							__UpperCAmelCase            =       calculate_waitingtime(arrival_time, burst_time, no_of_processes)
							__UpperCAmelCase            =       calculate_turnaroundtime(
							    burst_time, no_of_processes, waiting_time
							)

							# Printing the Result
							print("""PID\tBurst Time\tArrival Time\tWaiting Time\tTurnaround Time""")
							for i, process_id in enumerate(list(range(1, 5))):
														print(
														    f'''{process_id}\t{burst_time[i]}\t\t\t{arrival_time[i]}\t\t\t\t'''
														    f'''{waiting_time[i]}\t\t\t\t{turn_around_time[i]}'''
														)
							print(f'''\nAverage waiting time = {mean(waiting_time):.5f}''')
							print(f'''Average turnaround time = {mean(turn_around_time):.5f}''')



