



from __future__ import annotations

from queue import Queue



class 		_lowercase		:

   def __init__(   self      :							Any				)							->					None:


    """simple docstring"""






    a							=		{}

   def 		A				(   self      :							Dict				)							->					None:


    """simple docstring"""






    for i in self.vertices:
     print(__lowerCAmelCase				, " : "				, " -> ".join([str(__lowerCAmelCase				) for j in self.vertices[i]]				)				)

   def 		A				(   self      :							Dict				, __lowerCAmelCase      :							int				, __lowerCAmelCase      :							int				)							->					None:


    """simple docstring"""






    if from_vertex in self.vertices:
     self.vertices[from_vertex].append(__lowerCAmelCase				)
    else:
     a							=		[to_vertex]




   def 		A				(   self      :							List[Any]				, __lowerCAmelCase      :							int				)							->					set[int]:


    """simple docstring"""






    a							=		set()

    # create a first in first out queue to store all the vertices for BFS
    a							=		Queue()

    # mark the source node as visited and enqueue it
    visited.add(__lowerCAmelCase				)
    queue.put(__lowerCAmelCase				)

    while not queue.empty():
     a							=		queue.get()

     # loop through all adjacent vertex and enqueue it if not yet visited
     for adjacent_vertex in self.vertices[vertex]:
      if adjacent_vertex not in visited:
       queue.put(__lowerCAmelCase				)
       visited.add(__lowerCAmelCase				)
    return visited


if __name__ == "__main__":
     from doctest import testmod

     testmod(verbose=True)

     A_		:  Tuple										=  Graph()
     g.add_edge(0, 1)
     g.add_edge(0, 2)
     g.add_edge(1, 2)
     g.add_edge(2, 0)
     g.add_edge(2, 3)
     g.add_edge(3, 3)

     g.print_graph()
     # 0  :  1 -> 2
     # 1  :  2
     # 2  :  0 -> 3
     # 3  :  3

     assert sorted(g.bfs(2)) == [0, 1, 2, 3]







"""simple docstring"""

from __future__ import annotations




def    snake_case__						(							lowerCAmelCase :		list[int]		):
					__snake_case        =						[0] * len(lowerCAmelCase		)
					for i in range(1					,       len(lowerCAmelCase		)		):
										__snake_case        =						duration_times[i - 1] + waiting_times[i - 1]
					return waiting_times




def    snake_case__						(							lowerCAmelCase :		list[int]					,       lowerCAmelCase :		list[int]		):
					return [
					    duration_time + waiting_times[i]
					    for i, duration_time in enumerate(lowerCAmelCase		)
					]




def    snake_case__						(							lowerCAmelCase :		list[int]		):
					return sum(lowerCAmelCase		) / len(lowerCAmelCase		)




def    snake_case__						(							lowerCAmelCase :		list[int]		):
					return sum(lowerCAmelCase		) / len(lowerCAmelCase		)


if __name__ == "__main__":
		# process id's
		UpperCamelCase__			:     str			       =				[1, 2, 3]

		# ensure that we actually have processes
		if len(processes) == 0:
				print("Zero amount of processes")
				raise SystemExit(0)

		# duration time of all processes
		UpperCamelCase__			:     Any			       =				[19, 8, 9]

		# ensure we can match each id to a duration time
		if len(duration_times) != len(processes):
				print("Unable to match all id's with their duration time")
				raise SystemExit(0)

		# get the waiting times and the turnaround times
		UpperCamelCase__			:     Optional[int]			       =				calculate_waiting_times(duration_times)
		UpperCamelCase__			:     Any			       =				calculate_turnaround_times(duration_times, waiting_times)

		# get the average times
		UpperCamelCase__			:     Optional[Any]			       =				calculate_average_waiting_time(waiting_times)
		UpperCamelCase__			:     Dict			       =				calculate_average_turnaround_time(turnaround_times)

		# print all the results
		print("Process ID\tDuration Time\tWaiting Time\tTurnaround Time")
		for i, process in enumerate(processes):
				print(
				    f'{process}\t\t{duration_times[i]}\t\t{waiting_times[i]}\t\t'
				    f'{turnaround_times[i]}'
				)
		print(f'Average waiting time = {average_waiting_time}')
		print(f'Average turn around time = {average_turnaround_time}')


