

"""simple docstring"""





from __future__ import annotations

def   __SCREAMING_SNAKE_CASE  (      A_						,     A_ ):
	print(f'Vertex\tShortest Distance from vertex {src}' )
	for i, d in enumerate(A_ ):
		print(f'{i}\t\t{d}' )

def   __SCREAMING_SNAKE_CASE  (      A_						,     A_						,     A_ ):
	for j in range(A_ ):
		lowerCAmelCase__				,lowerCAmelCase__				,lowerCAmelCase__	:						List[str]  				=	(graph[j][k] for k in ['''src''', '''dst''', '''weight'''])
		if distance[u] != float('''inf''' ) and distance[u] + w < distance[v]:
			return True
	return False

def   __SCREAMING_SNAKE_CASE  (      A_						,     A_						,     A_						,     A_ ):
	lowerCAmelCase__	:						str  				=	[float('''inf''' )] * vertex_count
	lowerCAmelCase__	:						str  				=	0.0

	for _ in range(vertex_count - 1 ):
		for j in range(A_ ):
			lowerCAmelCase__				,lowerCAmelCase__				,lowerCAmelCase__	:						Optional[Any]  				=	(graph[j][k] for k in ['''src''', '''dst''', '''weight'''])

			if distance[u] != float('''inf''' ) and distance[u] + w < distance[v]:
				lowerCAmelCase__	:						Union[str, Any]  				=	distance[u] + w

	lowerCAmelCase__	:						List[str]  				=	check_negative_cycle(A_						,     A_						,     A_ )
	if negative_cycle_exists:
		raise Exception('''Negative cycle found''' )

	return distance


if __name__ == "__main__":
							import doctest

							doctest.testmod()

							__UpperCamelCase  :      Dict							      =		int(input('''Enter number of vertices: ''').strip())
							__UpperCamelCase  :      Any							      =		int(input('''Enter number of edges: ''').strip())

							__UpperCamelCase  :      list[dict[str, int]]							      =		[{} for _ in range(E)]

							for i in range(E):
														print('''Edge ''', i + 1)
														__UpperCamelCase      ,    __UpperCamelCase      ,    __UpperCamelCase  :      Union[str, Any]							      =		(
														    int(x)
														    for x in input('''Enter source, destination, weight: ''').strip().split(''' ''')
														)
														__UpperCamelCase  :      Optional[Any]							      =		{'''src''': src, '''dst''': dest, '''weight''': weight}

							__UpperCamelCase  :      Optional[Any]							      =		int(input('''\nEnter shortest path source:''').strip())
							__UpperCamelCase  :      Optional[Any]							      =		bellman_ford(graph, V, E, source)
							print_distance(shortest_distance, 0)





import builtins
import sys

from ...utils.imports import _is_package_available
from . import cursor, input
from .helpers import Direction, clear_line, forceWrite, linebreak, move_cursor, reset_cursor, writeColor
from .keymap import KEYMAP


a_    					=       False
try:
   a_    					=       _is_package_available('google.colab')
except ModuleNotFoundError:
   pass





@input.register
class 		_lowercase						:

 def __init__( self	:							Dict   ,      snake_case	:							str = None   ,      snake_case	:							list = []			)   ->						Union[str, Any]:

  """simple docstring"""





  UpperCamelCase_					:						Any =					0
  UpperCamelCase_					:						Optional[Any] =					choices
  UpperCamelCase_					:						Any =					prompt
  if sys.platform == "win32":
   UpperCamelCase_					:						Optional[Any] =					'*'
  else:
   UpperCamelCase_					:						str =					'➔ '

 def 						SCREAMING_SNAKE_CASE__   ( self	:							Optional[int]   ,      snake_case	:							List[str]   ,      snake_case	:							str = ""			)   ->						List[Any]:

  """simple docstring"""





  if sys.platform != "win32":
   writeColor(self.choices[index]   ,      3_2   ,      snake_case			)
  else:
   forceWrite(self.choices[index]   ,      snake_case			)

 def 						SCREAMING_SNAKE_CASE__   ( self	:							List[str]   ,      snake_case	:							int			)   ->						List[Any]:

  """simple docstring"""





  if index == self.position:
   forceWrite(f" {self.arrow_char} "			)
   self.write_choice(snake_case			)
  else:
   forceWrite(f"    {self.choices[index]}"			)
  reset_cursor()

 def 						SCREAMING_SNAKE_CASE__   ( self	:							Any   ,      snake_case	:							Direction   ,      snake_case	:							int = 1			)   ->						List[str]:

  """simple docstring"""





  UpperCamelCase_					:						Any =					self.position
  if direction == Direction.DOWN:
   if self.position + 1 >= len(self.choices			):
    return
   self.position += num_spaces
  else:
   if self.position - 1 < 0:
    return
   self.position -= num_spaces
  clear_line()
  self.print_choice(snake_case			)
  move_cursor(snake_case   ,      direction.name			)
  self.print_choice(self.position			)

 @input.mark(KEYMAP['up']			)
 def 						SCREAMING_SNAKE_CASE__   ( self	:							Optional[int]			)   ->						List[Any]:

  """simple docstring"""





  self.move_direction(Direction.UP			)

 @input.mark(KEYMAP['down']			)
 def 						SCREAMING_SNAKE_CASE__   ( self	:							Optional[int]			)   ->						Optional[Any]:

  """simple docstring"""





  self.move_direction(Direction.DOWN			)

 @input.mark(KEYMAP['newline']			)
 def 						SCREAMING_SNAKE_CASE__   ( self	:							str			)   ->						Optional[int]:

  """simple docstring"""





  move_cursor(len(self.choices			) - self.position   ,      'DOWN'			)
  return self.position

 @input.mark(KEYMAP['interrupt']			)
 def 						SCREAMING_SNAKE_CASE__   ( self	:							Optional[Any]			)   ->						Optional[Any]:

  """simple docstring"""





  move_cursor(len(self.choices			) - self.position   ,      'DOWN'			)
  raise KeyboardInterrupt

 @input.mark_multiple(*[KEYMAP[str(snake_case			)] for number in range(1_0			)]			)
 def 						SCREAMING_SNAKE_CASE__   ( self	:							int			)   ->						Dict:

  """simple docstring"""





  UpperCamelCase_					:						List[Any] =					int(chr(self.current_selection			)			)
  UpperCamelCase_					:						Optional[int] =					index - self.position
  if index == self.position:
   return
  if index < len(self.choices			):
   if self.position > index:
    self.move_direction(Direction.UP   ,      -movement			)
   elif self.position < index:
    self.move_direction(Direction.DOWN   ,      snake_case			)
   else:
    return
  else:
   return


 def 						SCREAMING_SNAKE_CASE__   ( self	:							List[Any]   ,      snake_case	:							int = 0			)   ->						Union[str, Any]:

  """simple docstring"""





  if self.prompt:
   linebreak()
   forceWrite(self.prompt   ,      '\n'			)
   if in_colab:
    forceWrite('Please input a choice index (starting from 0), and press enter'   ,      '\n'			)
   else:
    forceWrite('Please select a choice using the arrow or number keys, and selecting with enter'   ,      '\n'			)
  UpperCamelCase_					:						Optional[int] =					default_choice
  for i in range(len(self.choices			)			):
   self.print_choice(snake_case			)
   forceWrite('\n'			)
  move_cursor(len(self.choices			) - self.position   ,      'UP'			)
  with cursor.hide():
   while True:
    if in_colab:
     try:
      UpperCamelCase_					:						Tuple =					int(builtins.input()			)
     except ValueError:
      UpperCamelCase_					:						Tuple =					default_choice
    else:
     UpperCamelCase_					:						Optional[Any] =					self.handle_input()
    if choice is not None:
     reset_cursor()
     for _ in range(len(self.choices			) + 1			):
      move_cursor(1   ,      'UP'			)
      clear_line()
     self.write_choice(snake_case   ,      '\n'			)
     return choice



