




from __future__ import annotations

def 			a   (_lowerCAmelCase  ,    _lowerCAmelCase     ):
							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     ):
							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 			a   (_lowerCAmelCase  ,    _lowerCAmelCase  ,    _lowerCAmelCase  ,    _lowerCAmelCase     ):
							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()

			__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						,    __SCREAMING_SNAKE_CASE						,    __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)








import unittest

import numpy as np

from transformers.testing_utils import is_flaky, require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
			import torch

if is_vision_available():
			from PIL import Image

			from transformers import DonutImageProcessor






class  __magic_name__						(  unittest.TestCase):
				'''simple docstring'''







				def __init__(							self:   Union[str, Any]		,					_lowerCamelCase:   List[str]		,					_lowerCamelCase:   Union[str, Any]=7		,					_lowerCamelCase:   int=3		,					_lowerCamelCase:   Optional[int]=18		,					_lowerCamelCase:   Optional[Any]=30		,					_lowerCamelCase:   Any=4_00		,					_lowerCamelCase:   List[str]=True		,					_lowerCamelCase:   str=None		,					_lowerCamelCase:   Union[str, Any]=True		,					_lowerCamelCase:   Union[str, Any]=False		,					_lowerCamelCase:   int=True		,					_lowerCamelCase:   Any=True		,					_lowerCamelCase:   List[str]=[0.5, 0.5, 0.5]		,					_lowerCamelCase:   Dict=[0.5, 0.5, 0.5]		,					):
											SCREAMING_SNAKE_CASE_   	=    parent
											SCREAMING_SNAKE_CASE_   	=    batch_size
											SCREAMING_SNAKE_CASE_   	=    num_channels
											SCREAMING_SNAKE_CASE_   	=    image_size
											SCREAMING_SNAKE_CASE_   	=    min_resolution
											SCREAMING_SNAKE_CASE_   	=    max_resolution
											SCREAMING_SNAKE_CASE_   	=    do_resize
											SCREAMING_SNAKE_CASE_   	=    size if size is not None else {'''height''': 18, '''width''': 20}
											SCREAMING_SNAKE_CASE_   	=    do_thumbnail
											SCREAMING_SNAKE_CASE_   	=    do_align_axis
											SCREAMING_SNAKE_CASE_   	=    do_pad
											SCREAMING_SNAKE_CASE_   	=    do_normalize
											SCREAMING_SNAKE_CASE_   	=    image_mean
											SCREAMING_SNAKE_CASE_   	=    image_std





				def     _A							(							self:   str		):
											return {
											    "do_resize": self.do_resize,
											    "size": self.size,
											    "do_thumbnail": self.do_thumbnail,
											    "do_align_long_axis": self.do_align_axis,
											    "do_pad": self.do_pad,
											    "do_normalize": self.do_normalize,
											    "image_mean": self.image_mean,
											    "image_std": self.image_std,
											}






@require_torch
@require_vision
class  __magic_name__						(  __UpperCAmelCase    ,  unittest.TestCase):
				'''simple docstring'''







				SCREAMING_SNAKE_CASE__					:							Dict	      =					DonutImageProcessor if is_vision_available() else None


				def     _A							(							self:   Optional[int]		):
											SCREAMING_SNAKE_CASE_   	=    DonutImageProcessingTester(self		)


				@property
				def     _A							(							self:   List[str]		):
											return self.image_processor_tester.prepare_image_processor_dict()


				def     _A							(							self:   Union[str, Any]		):
											SCREAMING_SNAKE_CASE_   	=    self.image_processing_class(**self.image_processor_dict		)
											self.assertTrue(hasattr(_lowerCamelCase		,					'''do_resize'''		)		)
											self.assertTrue(hasattr(_lowerCamelCase		,					'''size'''		)		)
											self.assertTrue(hasattr(_lowerCamelCase		,					'''do_thumbnail'''		)		)
											self.assertTrue(hasattr(_lowerCamelCase		,					'''do_align_long_axis'''		)		)
											self.assertTrue(hasattr(_lowerCamelCase		,					'''do_pad'''		)		)
											self.assertTrue(hasattr(_lowerCamelCase		,					'''do_normalize'''		)		)
											self.assertTrue(hasattr(_lowerCamelCase		,					'''image_mean'''		)		)
											self.assertTrue(hasattr(_lowerCamelCase		,					'''image_std'''		)		)


				def     _A							(							self:   List[str]		):
											SCREAMING_SNAKE_CASE_   	=    self.image_processing_class.from_dict(self.image_processor_dict		)
											self.assertEqual(image_processor.size		,					{'''height''': 18, '''width''': 20}		)

											SCREAMING_SNAKE_CASE_   	=    self.image_processing_class.from_dict(self.image_processor_dict		,					size=42		)
											self.assertEqual(image_processor.size		,					{'''height''': 42, '''width''': 42}		)

											# Previous config had dimensions in (width, height) order
											SCREAMING_SNAKE_CASE_   	=    self.image_processing_class.from_dict(self.image_processor_dict		,					size=(42, 84)		)
											self.assertEqual(image_processor.size		,					{'''height''': 84, '''width''': 42}		)


				def     _A							(							self:   List[Any]		):
											pass


				@is_flaky()
				def     _A							(							self:   int		):
											# Initialize image_processing
											SCREAMING_SNAKE_CASE_   	=    self.image_processing_class(**self.image_processor_dict		)
											# create random PIL images
											SCREAMING_SNAKE_CASE_   	=    prepare_image_inputs(self.image_processor_tester		,					equal_resolution=_lowerCamelCase		)
											for image in image_inputs:
																		self.assertIsInstance(_lowerCamelCase		,					Image.Image		)

											# Test not batched input
											SCREAMING_SNAKE_CASE_   	=    image_processing(image_inputs[0]		,					return_tensors='''pt'''		).pixel_values
											self.assertEqual(
											    encoded_images.shape		,					(
											        1,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.size['''height'''],
											        self.image_processor_tester.size['''width'''],
											    )		,					)

											# Test batched
											SCREAMING_SNAKE_CASE_   	=    image_processing(_lowerCamelCase		,					return_tensors='''pt'''		).pixel_values
											self.assertEqual(
											    encoded_images.shape		,					(
											        self.image_processor_tester.batch_size,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.size['''height'''],
											        self.image_processor_tester.size['''width'''],
											    )		,					)


				@is_flaky()
				def     _A							(							self:   Optional[Any]		):
											# Initialize image_processing
											SCREAMING_SNAKE_CASE_   	=    self.image_processing_class(**self.image_processor_dict		)
											# create random numpy tensors
											SCREAMING_SNAKE_CASE_   	=    prepare_image_inputs(self.image_processor_tester		,					equal_resolution=_lowerCamelCase		,					numpify=_lowerCamelCase		)
											for image in image_inputs:
																		self.assertIsInstance(_lowerCamelCase		,					np.ndarray		)

											# Test not batched input
											SCREAMING_SNAKE_CASE_   	=    image_processing(image_inputs[0]		,					return_tensors='''pt'''		).pixel_values
											self.assertEqual(
											    encoded_images.shape		,					(
											        1,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.size['''height'''],
											        self.image_processor_tester.size['''width'''],
											    )		,					)

											# Test batched
											SCREAMING_SNAKE_CASE_   	=    image_processing(_lowerCamelCase		,					return_tensors='''pt'''		).pixel_values
											self.assertEqual(
											    encoded_images.shape		,					(
											        self.image_processor_tester.batch_size,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.size['''height'''],
											        self.image_processor_tester.size['''width'''],
											    )		,					)





				@is_flaky()
				def     _A							(							self:   List[str]		):
											# Initialize image_processing
											SCREAMING_SNAKE_CASE_   	=    self.image_processing_class(**self.image_processor_dict		)
											# create random PyTorch tensors
											SCREAMING_SNAKE_CASE_   	=    prepare_image_inputs(self.image_processor_tester		,					equal_resolution=_lowerCamelCase		,					torchify=_lowerCamelCase		)
											for image in image_inputs:
																		self.assertIsInstance(_lowerCamelCase		,					torch.Tensor		)

											# Test not batched input
											SCREAMING_SNAKE_CASE_   	=    image_processing(image_inputs[0]		,					return_tensors='''pt'''		).pixel_values
											self.assertEqual(
											    encoded_images.shape		,					(
											        1,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.size['''height'''],
											        self.image_processor_tester.size['''width'''],
											    )		,					)

											# Test batched
											SCREAMING_SNAKE_CASE_   	=    image_processing(_lowerCamelCase		,					return_tensors='''pt'''		).pixel_values
											self.assertEqual(
											    encoded_images.shape		,					(
											        self.image_processor_tester.batch_size,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.size['''height'''],
											        self.image_processor_tester.size['''width'''],
											    )		,					)


