






from __future__ import annotations


def __A    (      __lowerCAmelCase ,		__lowerCAmelCase	)->  Any:





						"""simple docstring"""



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


def __A    (      __lowerCAmelCase ,		__lowerCAmelCase ,		__lowerCAmelCase	)->  Union[str, Any]:





						"""simple docstring"""



						for j in range(__lowerCAmelCase	):
												_UpperCAmelCase					, _UpperCAmelCase					, _UpperCAmelCase									=			(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 __A    (      __lowerCAmelCase ,		__lowerCAmelCase ,		__lowerCAmelCase ,		__lowerCAmelCase	)->  list[float]:





						"""simple docstring"""



						_UpperCAmelCase									=			[float('inf'	)] * vertex_count
						_UpperCAmelCase									=			0.0

						for _ in range(vertex_count - 1	):
												for j in range(__lowerCAmelCase	):
																		_UpperCAmelCase					, _UpperCAmelCase					, _UpperCAmelCase									=			(graph[j][k] for k in ['src', 'dst', 'weight'])

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

						_UpperCAmelCase									=			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      	=  int(input('''Enter number of vertices: ''').strip())
		_a      	=  int(input('''Enter number of edges: ''').strip())

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

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

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








import unittest

import torch
from torch import nn

from accelerate.test_utils import require_cuda
from accelerate.utils.memory import find_executable_batch_size, release_memory


def __A    (      )->  Tuple:





						"""simple docstring"""



						raise RuntimeError('CUDA out of memory.'	)





class __lowerCamelCase (      nn.Module):





	"""simple docstring"""






	def __init__(							self    ):
							"""simple docstring"""







							super().__init__()
							_UpperCAmelCase									=			nn.Linear(3       ,    4    )
							_UpperCAmelCase									=			nn.BatchNormad(4    )
							_UpperCAmelCase									=			nn.Linear(4       ,    5    )

	def        UpperCamelCase    (							self       ,    UpperCAmelCase    ):
							"""simple docstring"""







							return self.lineara(self.batchnorm(self.lineara(UpperCAmelCase    )    )    )





class __lowerCamelCase (      unittest.TestCase):





	"""simple docstring"""






	def        UpperCamelCase    (							self    ):
							"""simple docstring"""







							_UpperCAmelCase									=			[]

							@find_executable_batch_size(starting_batch_size=128    )
							def mock_training_loop_function(UpperCAmelCase    ):
													nonlocal batch_sizes
													batch_sizes.append(UpperCAmelCase    )
													if batch_size != 8:
																			raise_fake_out_of_memory()

							mock_training_loop_function()
							self.assertListEqual(UpperCAmelCase       ,    [128, 64, 32, 16, 8]    )

	def        UpperCamelCase    (							self    ):
							"""simple docstring"""







							_UpperCAmelCase									=			[]

							@find_executable_batch_size(starting_batch_size=128    )
							def mock_training_loop_function(UpperCAmelCase       ,    UpperCAmelCase    ):
													nonlocal batch_sizes
													batch_sizes.append(UpperCAmelCase    )
													if batch_size != 8:
																			raise_fake_out_of_memory()
													return batch_size, arga

							_UpperCAmelCase					, _UpperCAmelCase									=			mock_training_loop_function('hello'    )
							self.assertListEqual(UpperCAmelCase       ,    [128, 64, 32, 16, 8]    )
							self.assertListEqual([bs, arga]       ,    [8, 'hello']    )

	def        UpperCamelCase    (							self    ):
							"""simple docstring"""







							@find_executable_batch_size(starting_batch_size=0    )
							def mock_training_loop_function(UpperCAmelCase    ):
													pass

							with self.assertRaises(UpperCAmelCase    ) as cm:
													mock_training_loop_function()
													self.assertIn('No executable batch size found, reached zero.'       ,    cm.exception.args[0]    )

	def        UpperCamelCase    (							self    ):
							"""simple docstring"""







							@find_executable_batch_size(starting_batch_size=16    )
							def mock_training_loop_function(UpperCAmelCase    ):
													if batch_size > 0:
																			raise_fake_out_of_memory()
													pass

							with self.assertRaises(UpperCAmelCase    ) as cm:
													mock_training_loop_function()
													self.assertIn('No executable batch size found, reached zero.'       ,    cm.exception.args[0]    )

	def        UpperCamelCase    (							self    ):
							"""simple docstring"""







							@find_executable_batch_size(starting_batch_size=128    )
							def mock_training_loop_function(UpperCAmelCase       ,    UpperCAmelCase       ,    UpperCAmelCase    ):
													if batch_size != 8:
																			raise raise_fake_out_of_memory()

							with self.assertRaises(UpperCAmelCase    ) as cm:
													mock_training_loop_function(128       ,    'hello'       ,    'world'    )
													self.assertIn('Batch size was passed into `f`'       ,    cm.exception.args[0]    )
													self.assertIn('`f(arg1=\'hello\', arg2=\'world\')'       ,    cm.exception.args[0]    )

	def        UpperCamelCase    (							self    ):
							"""simple docstring"""







							@find_executable_batch_size(starting_batch_size=16    )
							def mock_training_loop_function(UpperCAmelCase    ):
													raise ValueError('Oops, we had an error!'    )

							with self.assertRaises(UpperCAmelCase    ) as cm:
													mock_training_loop_function()
													self.assertIn('Oops, we had an error!'       ,    cm.exception.args[0]    )

	@require_cuda
	def        UpperCamelCase    (							self    ):
							"""simple docstring"""







							_UpperCAmelCase									=			torch.cuda.memory_allocated()
							_UpperCAmelCase									=			ModelForTest()
							model.cuda()
							self.assertGreater(torch.cuda.memory_allocated()       ,    UpperCAmelCase    )
							_UpperCAmelCase									=			release_memory(UpperCAmelCase    )
							self.assertEqual(torch.cuda.memory_allocated()       ,    UpperCAmelCase    )
