


"""simple docstring"""







from abc import ABC, abstractmethod
from typing import Optional, Union

from .. import Dataset, DatasetDict, Features, IterableDataset, IterableDatasetDict, NamedSplit
from ..utils.typing import NestedDataStructureLike, PathLike




class 			UpperCamelCase_     (			UpperCamelCase):

	"""simple docstring"""





	def __init__(			self      :    Any      ,      UpperCAmelCase__      :    Optional[NestedDataStructureLike[PathLike]] = None      ,      UpperCAmelCase__      :    Optional[NamedSplit] = None      ,      UpperCAmelCase__      :    Optional[Features] = None      ,      UpperCAmelCase__      :    str = None      ,      UpperCAmelCase__      :    bool = False      ,      UpperCAmelCase__      :    bool = False      ,      UpperCAmelCase__      :    Optional[int] = None      ,      **UpperCAmelCase__      :    Optional[int]      ,      )	->     Dict:
						__SCREAMING_SNAKE_CASE						       =    path_or_paths
						__SCREAMING_SNAKE_CASE						       =    split if split or isinstance(UpperCAmelCase__      ,      UpperCAmelCase__       ) else "train"
						__SCREAMING_SNAKE_CASE						       =    features
						__SCREAMING_SNAKE_CASE						       =    cache_dir
						__SCREAMING_SNAKE_CASE						       =    keep_in_memory
						__SCREAMING_SNAKE_CASE						       =    streaming
						__SCREAMING_SNAKE_CASE						       =    num_proc
						__SCREAMING_SNAKE_CASE						       =    kwargs




	@abstractmethod
	def   UpperCAmelCase_				(			self      :    List[Any]       )	->     Union[Dataset, DatasetDict, IterableDataset, IterableDatasetDict]:
						pass






class 			UpperCamelCase_     (			UpperCamelCase):

	"""simple docstring"""





	def __init__(			self      :    Any      ,      UpperCAmelCase__      :    Optional[Features] = None      ,      UpperCAmelCase__      :    str = None      ,      UpperCAmelCase__      :    bool = False      ,      UpperCAmelCase__      :    bool = False      ,      UpperCAmelCase__      :    Optional[int] = None      ,      **UpperCAmelCase__      :    int      ,      )	->     Optional[int]:
						__SCREAMING_SNAKE_CASE						       =    features
						__SCREAMING_SNAKE_CASE						       =    cache_dir
						__SCREAMING_SNAKE_CASE						       =    keep_in_memory
						__SCREAMING_SNAKE_CASE						       =    streaming
						__SCREAMING_SNAKE_CASE						       =    num_proc
						__SCREAMING_SNAKE_CASE						       =    kwargs




	@abstractmethod
	def   UpperCAmelCase_				(			self      :    Union[str, Any]       )	->     Union[Dataset, IterableDataset]:
						pass




"""simple docstring"""







from __future__ import annotations




def        UpperCAmelCase__	(lowerCAmelCase_  ,						lowerCAmelCase_       ):




					'''simple docstring'''


					print(f"""Vertex\tShortest Distance from vertex {src}"""       )
					for i, d in enumerate(lowerCAmelCase_       ):
										print(f"""{i}\t\t{d}"""       )




def        UpperCAmelCase__	(lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_       ):




					'''simple docstring'''


					for j in range(lowerCAmelCase_       ):
										__SCREAMING_SNAKE_CASE       ,  __SCREAMING_SNAKE_CASE       ,  __SCREAMING_SNAKE_CASE						       =    (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        UpperCAmelCase__	(lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_       ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						       =    [float("inf"       )] * vertex_count
					__SCREAMING_SNAKE_CASE						       =    0.0

					for _ in range(vertex_count - 1       ):
										for j in range(lowerCAmelCase_       ):
															__SCREAMING_SNAKE_CASE       ,  __SCREAMING_SNAKE_CASE       ,  __SCREAMING_SNAKE_CASE						       =    (graph[j][k] for k in ["src", "dst", "weight"])

															if distance[u] != float("inf"       ) and distance[u] + w < distance[v]:
																				__SCREAMING_SNAKE_CASE						       =    distance[u] + w

					__SCREAMING_SNAKE_CASE						       =    check_negative_cycle(lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_       )
					if negative_cycle_exists:
										raise Exception("Negative cycle found"       )

					return distance


if __name__ == "__main__":
		import doctest

		doctest.testmod()

		a__    :							Union[str, Any]            =					int(input('''Enter number of vertices: ''').strip())
		a__    :							Any            =					int(input('''Enter number of edges: ''').strip())

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

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

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