


'''simple docstring'''




import unittest

import numpy as np

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

from ...test_image_processing_common import ImageProcessingSavingTestMixin


if is_torch_available():
				import torch

if is_vision_available():
				from PIL import Image

				from transformers import TvltImageProcessor





def 				a_							(    lowercase				,    lowercase=10				,    lowercase=10				,    lowercase=False				,    lowercase=False     )      ->int:






				'''simple docstring'''

				__lowerCamelCase		:   List[Any]           =       []
				for i in range(image_processor_tester.num_frames     ):
								video.append(np.random.randint(255				,    size=(image_processor_tester.num_channels, width, height)				,    dtype=np.uinta     )     )

				if not numpify and not torchify:
								# PIL expects the channel dimension as last dimension
								__lowerCamelCase		:   Dict           =       [Image.fromarray(np.moveaxis(lowercase				,    0				,    -1     )     ) for frame in video]

				if torchify:
								__lowerCamelCase		:   List[Any]           =       [torch.from_numpy(lowercase     ) for frame in video]

				return video





def 				a_							(    lowercase				,    lowercase=False				,    lowercase=False				,    lowercase=False     )      ->Optional[Any]:






				'''simple docstring'''

				assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

				__lowerCamelCase		:   Tuple           =       []
				for i in range(image_processor_tester.batch_size     ):
								if equal_resolution:
												__lowerCamelCase		:   Dict           =       image_processor_tester.max_resolution
								else:
												__lowerCamelCase    ,       __lowerCamelCase		:   str           =       np.random.choice(
												    np.arange(image_processor_tester.min_resolution				,    image_processor_tester.max_resolution     )				,    2     )
												__lowerCamelCase		:   List[str]           =       prepare_video(
												    image_processor_tester=lowercase				,    width=lowercase				,    height=lowercase				,    numpify=lowercase				,    torchify=lowercase				,    )
								video_inputs.append(lowercase     )

				return video_inputs





class _snake_case (			unittest.TestCase ):
							"""simple docstring"""





							def __init__( self      ,					__A      ,					__A=7      ,					__A=3      ,					__A=4      ,					__A=18      ,					__A=30      ,					__A=400      ,					__A=True      ,					__A=None      ,					__A=True      ,					__A=[0.5, 0.5, 0.5]      ,					__A=[0.5, 0.5, 0.5]      ,					__A=True      ,					__A=None      ,					)  ->List[Any]:



											"""simple docstring"""







											__lowerCamelCase		:   Union[str, Any]           =       size if size is not None else {"shortest_edge": 18}
											__lowerCamelCase		:   Dict           =       crop_size if crop_size is not None else {"height": 18, "width": 18}

											__lowerCamelCase		:   str           =       parent
											__lowerCamelCase		:   Dict           =       batch_size
											__lowerCamelCase		:   Tuple           =       num_channels
											__lowerCamelCase		:   Optional[Any]           =       num_frames
											__lowerCamelCase		:   Optional[int]           =       image_size
											__lowerCamelCase		:   Union[str, Any]           =       min_resolution
											__lowerCamelCase		:   Optional[Any]           =       max_resolution
											__lowerCamelCase		:   Tuple           =       do_resize
											__lowerCamelCase		:   List[Any]           =       size
											__lowerCamelCase		:   Optional[Any]           =       do_normalize
											__lowerCamelCase		:   Dict           =       image_mean
											__lowerCamelCase		:   List[Any]           =       image_std
											__lowerCamelCase		:   Tuple           =       do_center_crop
											__lowerCamelCase		:   Tuple           =       crop_size







							def 		__SCREAMING_SNAKE_CASE( self						)  ->Union[str, Any]:



											"""simple docstring"""







											return {
											    "image_mean": self.image_mean,
											    "image_std": self.image_std,
											    "do_normalize": self.do_normalize,
											    "do_resize": self.do_resize,
											    "size": self.size,
											    "do_center_crop": self.do_center_crop,
											    "crop_size": self.crop_size,
											}





@require_torch
@require_vision
class _snake_case (			a__     , unittest.TestCase ):
							"""simple docstring"""





							__a				       =  TvltImageProcessor if is_vision_available() else None







							def 		__SCREAMING_SNAKE_CASE( self						)  ->Dict:



											"""simple docstring"""







											__lowerCamelCase		:   str           =       TvltImageProcessorTester(self						)







							@property
							def 		__SCREAMING_SNAKE_CASE( self						)  ->List[Any]:



											"""simple docstring"""







											return self.image_processor_tester.prepare_image_processor_dict()







							def 		__SCREAMING_SNAKE_CASE( self						)  ->str:



											"""simple docstring"""







											__lowerCamelCase		:   Any           =       self.image_processing_class(**self.image_processor_dict						)
											self.assertTrue(hasattr(__A      ,					"image_mean"						)						)
											self.assertTrue(hasattr(__A      ,					"image_std"						)						)
											self.assertTrue(hasattr(__A      ,					"do_normalize"						)						)
											self.assertTrue(hasattr(__A      ,					"do_resize"						)						)
											self.assertTrue(hasattr(__A      ,					"do_center_crop"						)						)
											self.assertTrue(hasattr(__A      ,					"size"						)						)







							def 		__SCREAMING_SNAKE_CASE( self						)  ->Union[str, Any]:



											"""simple docstring"""







											__lowerCamelCase		:   Union[str, Any]           =       self.image_processing_class(**self.image_processor_dict						)
											# create random PIL videos
											__lowerCamelCase		:   Dict           =       prepare_video_inputs(self.image_processor_tester      ,					equal_resolution=__A						)
											for video in video_inputs:
															self.assertIsInstance(__A      ,					__A						)
															self.assertIsInstance(video[0]      ,					Image.Image						)

											# Test not batched input
											__lowerCamelCase		:   Optional[Any]           =       image_processor(video_inputs[0]      ,					return_tensors="pt"						).pixel_values
											self.assertEqual(
											    encoded_videos.shape      ,					(
											        1,
											        self.image_processor_tester.num_frames,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.crop_size["height"],
											        self.image_processor_tester.crop_size["width"],
											    )      ,					)

											# Test batched
											__lowerCamelCase		:   str           =       image_processor(__A      ,					return_tensors="pt"						).pixel_values
											self.assertEqual(
											    encoded_videos.shape      ,					(
											        self.image_processor_tester.batch_size,
											        self.image_processor_tester.num_frames,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.crop_size["height"],
											        self.image_processor_tester.crop_size["width"],
											    )      ,					)







							def 		__SCREAMING_SNAKE_CASE( self						)  ->Optional[Any]:



											"""simple docstring"""







											__lowerCamelCase		:   Tuple           =       self.image_processing_class(**self.image_processor_dict						)
											# create random numpy tensors
											__lowerCamelCase		:   int           =       prepare_video_inputs(self.image_processor_tester      ,					equal_resolution=__A      ,					numpify=__A						)
											for video in video_inputs:
															self.assertIsInstance(__A      ,					__A						)
															self.assertIsInstance(video[0]      ,					np.ndarray						)

											# Test not batched input
											__lowerCamelCase		:   List[str]           =       image_processor(video_inputs[0]      ,					return_tensors="pt"						).pixel_values
											self.assertEqual(
											    encoded_videos.shape      ,					(
											        1,
											        self.image_processor_tester.num_frames,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.crop_size["height"],
											        self.image_processor_tester.crop_size["width"],
											    )      ,					)

											# Test batched
											__lowerCamelCase		:   List[Any]           =       image_processor(__A      ,					return_tensors="pt"						).pixel_values
											self.assertEqual(
											    encoded_videos.shape      ,					(
											        self.image_processor_tester.batch_size,
											        self.image_processor_tester.num_frames,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.crop_size["height"],
											        self.image_processor_tester.crop_size["width"],
											    )      ,					)







							def 		__SCREAMING_SNAKE_CASE( self						)  ->Optional[Any]:



											"""simple docstring"""







											__lowerCamelCase		:   Tuple           =       self.image_processing_class(**self.image_processor_dict						)
											# create random PyTorch tensors
											__lowerCamelCase		:   Tuple           =       prepare_video_inputs(self.image_processor_tester      ,					equal_resolution=__A      ,					torchify=__A						)
											for video in video_inputs:
															self.assertIsInstance(__A      ,					__A						)
															self.assertIsInstance(video[0]      ,					torch.Tensor						)

											# Test not batched input
											__lowerCamelCase		:   Dict           =       image_processor(video_inputs[0]      ,					return_tensors="pt"						).pixel_values
											self.assertEqual(
											    encoded_videos.shape      ,					(
											        1,
											        self.image_processor_tester.num_frames,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.crop_size["height"],
											        self.image_processor_tester.crop_size["width"],
											    )      ,					)

											# Test batched
											__lowerCamelCase		:   str           =       image_processor(__A      ,					return_tensors="pt"						).pixel_values
											self.assertEqual(
											    encoded_videos.shape      ,					(
											        self.image_processor_tester.batch_size,
											        self.image_processor_tester.num_frames,
											        self.image_processor_tester.num_channels,
											        self.image_processor_tester.crop_size["height"],
											        self.image_processor_tester.crop_size["width"],
											    )      ,					)









'''simple docstring'''




from collections import deque





def 				a_							(    lowercase     )      ->Tuple:






				'''simple docstring'''

				return input(lowercase     ).strip().split(" "     )





def 				a_							(    lowercase				,    lowercase     )      ->dict[int, list[int]]:






				'''simple docstring'''

				__lowerCamelCase		:   dict[int, list[int]]           =       {}
				for i in range(lowercase     ):
								__lowerCamelCase		:   int           =       []

				for e in range(lowercase     ):
								__lowerCamelCase    ,       __lowerCamelCase		:   int           =       (int(lowercase     ) for i in _input(F'Edge {e + 1}: <node1> <node2> '     ))
								graph[x].append(lowercase     )
				return graph





def 				a_							(    lowercase				,    lowercase     )      ->dict[int, list[int]]:






				'''simple docstring'''

				__lowerCamelCase		:   dict[int, list[int]]           =       {}
				for i in range(lowercase     ):
								__lowerCamelCase		:   Any           =       []

				for e in range(lowercase     ):
								__lowerCamelCase    ,       __lowerCamelCase		:   Dict           =       (int(lowercase     ) for i in _input(F'Edge {e + 1}: <node1> <node2> '     ))
								graph[x].append(lowercase     )
								graph[y].append(lowercase     )
				return graph





def 				a_							(    lowercase				,    lowercase     )      ->dict[int, list[tuple[int, int]]]:






				'''simple docstring'''

				__lowerCamelCase		:   dict[int, list[tuple[int, int]]]           =       {}
				for i in range(lowercase     ):
								__lowerCamelCase		:   List[Any]           =       []

				for e in range(lowercase     ):
								__lowerCamelCase    ,       __lowerCamelCase    ,       __lowerCamelCase		:   int           =       (int(lowercase     ) for i in _input(F'Edge {e + 1}: <node1> <node2> <weight> '     ))
								graph[x].append((y, w)     )
								graph[y].append((x, w)     )
				return graph


if __name__ == "__main__":
				__lowercase		,		__lowercase	:   List[Any]   		=					(int(i) for i in _input("""Number of nodes and edges: """))

				__lowercase	:   Any   		=					int(
				    _input(
				        """Press 1 or 2 or 3 \n"""
				        """1. Unweighted directed \n"""
				        """2. Unweighted undirected \n"""
				        """3. Weighted undirected \n"""
				    )[0]
				)

				__lowercase	:   Any   		=					{
				    1: initialize_unweighted_directed_graph,
				    2: initialize_unweighted_undirected_graph,
				    3: initialize_weighted_undirected_graph,
				}[graph_choice](n, m)





def 				a_							(    lowercase				,    lowercase     )      ->Tuple:






				'''simple docstring'''

				__lowerCamelCase    ,       __lowerCamelCase		:   Dict           =       {s}, [s]
				print(lowercase     )
				while _s:
								__lowerCamelCase		:   int           =       0
								for i in g[_s[-1]]:
												if i not in vis:
																_s.append(lowercase     )
																vis.add(lowercase     )
																__lowerCamelCase		:   Tuple           =       1
																print(lowercase     )
																break
								if not flag:
												_s.pop()





def 				a_							(    lowercase				,    lowercase     )      ->List[str]:






				'''simple docstring'''

				__lowerCamelCase    ,       __lowerCamelCase		:   Tuple           =       {s}, deque([s]     )
				print(lowercase     )
				while q:
								__lowerCamelCase		:   Optional[Any]           =       q.popleft()
								for v in g[u]:
												if v not in vis:
																vis.add(lowercase     )
																q.append(lowercase     )
																print(lowercase     )





def 				a_							(    lowercase				,    lowercase     )      ->Any:






				'''simple docstring'''

				__lowerCamelCase    ,       __lowerCamelCase    ,       __lowerCamelCase		:   Optional[int]           =       {s: 0}, set(), {s: 0}
				while True:
								if len(lowercase     ) == len(lowercase     ) - 1:
												break
								__lowerCamelCase		:   str           =       10_0000
								for i in dist:
												if i not in known and dist[i] < mini:
																__lowerCamelCase		:   Any           =       dist[i]
																__lowerCamelCase		:   List[str]           =       i
								known.add(lowercase     )
								for v in g[u]:
												if v[0] not in known and dist[u] + v[1] < dist.get(v[0]				,    10_0000     ):
																__lowerCamelCase		:   Optional[int]           =       dist[u] + v[1]
																__lowerCamelCase		:   List[str]           =       u
				for i in dist:
								if i != s:
												print(dist[i]     )





def 				a_							(    lowercase				,    lowercase=None				,    lowercase=None     )      ->Optional[Any]:






				'''simple docstring'''

				if q is None:
								__lowerCamelCase		:   int           =       [1]
				if ind is None:
								__lowerCamelCase		:   Any           =       [0] * (len(lowercase     ) + 1)  # SInce oth Index is ignored
								for u in g:
												for v in g[u]:
																ind[v] += 1
								__lowerCamelCase		:   Tuple           =       deque()
								for i in g:
												if ind[i] == 0:
																q.append(lowercase     )
				if len(lowercase     ) == 0:
								return
				__lowerCamelCase		:   Optional[Any]           =       q.popleft()
				print(lowercase     )
				for w in g[v]:
								ind[w] -= 1
								if ind[w] == 0:
												q.append(lowercase     )
				topo(lowercase				,    lowercase				,    lowercase     )





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






				'''simple docstring'''

				__lowerCamelCase		:   Tuple           =       input().strip()
				__lowerCamelCase		:   Any           =       []
				for _ in range(lowercase     ):
								a.append(map(lowercase				,    input().strip().split()     )     )
				return a, n





def 				a_							(    lowercase     )      ->List[str]:






				'''simple docstring'''

				((__lowerCamelCase)    ,       (__lowerCamelCase))		:   Optional[int]           =       a_and_n
				__lowerCamelCase		:   Optional[int]           =       list(lowercase     )
				__lowerCamelCase		:   str           =       [[0] * n for i in range(lowercase     )]
				for k in range(lowercase     ):
								for i in range(lowercase     ):
												for j in range(lowercase     ):
																if dist[i][j] > dist[i][k] + dist[k][j]:
																				__lowerCamelCase		:   str           =       dist[i][k] + dist[k][j]
																				__lowerCamelCase		:   Tuple           =       k
				print(lowercase     )





def 				a_							(    lowercase				,    lowercase     )      ->Dict:






				'''simple docstring'''

				__lowerCamelCase    ,       __lowerCamelCase    ,       __lowerCamelCase		:   int           =       {s: 0}, set(), {s: 0}
				while True:
								if len(lowercase     ) == len(lowercase     ) - 1:
												break
								__lowerCamelCase		:   List[Any]           =       10_0000
								for i in dist:
												if i not in known and dist[i] < mini:
																__lowerCamelCase		:   str           =       dist[i]
																__lowerCamelCase		:   Optional[int]           =       i
								known.add(lowercase     )
								for v in g[u]:
												if v[0] not in known and v[1] < dist.get(v[0]				,    10_0000     ):
																__lowerCamelCase		:   Dict           =       v[1]
																__lowerCamelCase		:   List[str]           =       u
				return dist





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






				'''simple docstring'''

				__lowerCamelCase    ,       __lowerCamelCase		:   List[Any]           =       map(lowercase				,    input().split(" "     )     )
				__lowerCamelCase		:   Optional[Any]           =       []
				for _ in range(lowercase     ):
								edges.append(map(lowercase				,    input().split(" "     )     )     )
				return edges, n





def 				a_							(    lowercase     )      ->Optional[int]:






				'''simple docstring'''

				((__lowerCamelCase)    ,       (__lowerCamelCase))		:   Any           =       e_and_n
				e.sort(reverse=lowercase				,    key=lambda lowercase     : x[2]     )
				__lowerCamelCase		:   Optional[Any]           =       [{i} for i in range(1				,    n + 1     )]
				while True:
								if len(lowercase     ) == 1:
												break
								print(lowercase     )
								__lowerCamelCase		:   List[str]           =       e.pop()
								for i in range(len(lowercase     )     ):
												if x[0] in s[i]:
																break
								for j in range(len(lowercase     )     ):
												if x[1] in s[j]:
																if i == j:
																				break
																s[j].update(s[i]     )
																s.pop(lowercase     )
																break





def 				a_							(    lowercase     )      ->int:






				'''simple docstring'''

				__lowerCamelCase		:   Tuple           =       []
				for node in graph:
								if not graph[node]:
												isolated.append(lowercase     )
				return isolated





