

from __future__ import annotations

def 							__SCREAMING_SNAKE_CASE							(			lowerCAmelCase:					list[float]					, lowerCAmelCase:					Union[str, Any]	)				->    Any:
				print(F'Vertex\tShortest Distance from vertex {src}'	)
				for i, d in enumerate(snake_case_	):
								print(F'{i}\t\t{d}'	)

def 							__SCREAMING_SNAKE_CASE							(			lowerCAmelCase:					list[dict[str, int]]					, lowerCAmelCase:					list[float]					, lowerCAmelCase:					int	)				->    Any:




				for j in range(snake_case_	):
								_UpperCAmelCase						,							_UpperCAmelCase						,							_UpperCAmelCase    :						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							(			lowerCAmelCase:					list[dict[str, int]]					, lowerCAmelCase:					int					, lowerCAmelCase:					int					, lowerCAmelCase:					int	)				->    list[float]:
				_UpperCAmelCase    :						Optional[int]							=      [float("inf"	)] * vertex_count
				_UpperCAmelCase    :						Dict							=      0.0

				for _ in range(vertex_count - 1	):
								for j in range(snake_case_	):
												_UpperCAmelCase						,							_UpperCAmelCase						,							_UpperCAmelCase    :						Optional[Any]							=      (graph[j][k] for k in ["src", "dst", "weight"])

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

				_UpperCAmelCase    :						Tuple							=      check_negative_cycle(snake_case_					, snake_case_					, snake_case_	)
				if negative_cycle_exists:
								raise Exception("Negative cycle found"	)

				return distance


if __name__ == "__main__":
				import doctest

				doctest.testmod()

				SCREAMING_SNAKE_CASE_            = int(input('Enter number of vertices: ').strip())
				SCREAMING_SNAKE_CASE_            = int(input('Enter number of edges: ').strip())

				SCREAMING_SNAKE_CASE_            = [{} for _ in range(E)]

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

				SCREAMING_SNAKE_CASE_            = int(input('\nEnter shortest path source:').strip())
				SCREAMING_SNAKE_CASE_            = bellman_ford(graph, V, E, source)
				print_distance(shortest_distance, 0)





from typing import Any

class 			a					:


						def __init__(    self  ,   A_		):







										'''simple docstring'''


										_UpperCAmelCase    :						List[Any]							=      data
										_UpperCAmelCase    :						Any							=      None







class 			a					:


						def __init__(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						Union[str, Any]							=      None


						def     _UpperCAmelCase			(    self		):







										'''simple docstring'''


										_UpperCAmelCase    :						str							=      self.head
										while temp is not None:
														print(temp.data  ,   end=" "		)
														_UpperCAmelCase    :						str							=      temp.next
										print()


						def     _UpperCAmelCase			(    self  ,   A_		):







										'''simple docstring'''


										_UpperCAmelCase    :						Optional[int]							=      Node(A_		)
										_UpperCAmelCase    :						Tuple							=      self.head
										_UpperCAmelCase    :						Tuple							=      new_node





						def     _UpperCAmelCase			(    self  ,   A_  ,   A_		):







										'''simple docstring'''


										if node_data_a == node_data_a:
														return
										else:
														_UpperCAmelCase    :						int							=      self.head
														while node_a is not None and node_a.data != node_data_a:
																		_UpperCAmelCase    :						Tuple							=      node_a.next

														_UpperCAmelCase    :						Dict							=      self.head
														while node_a is not None and node_a.data != node_data_a:
																		_UpperCAmelCase    :						List[Any]							=      node_a.next

														if node_a is None or node_a is None:
																		return

														_UpperCAmelCase						,							_UpperCAmelCase    :						Optional[int]							=      node_a.data, node_a.data


if __name__ == "__main__":
					SCREAMING_SNAKE_CASE_            = LinkedList()
					for i in range(5, 0, -1):
										ll.push(i)

					ll.print_list()

					ll.swap_nodes(1, 4)
					print('After swapping')
					ll.print_list()


