





from collections import deque

def      __snake_case						(					_lowerCAmelCase : Any	) ->						int:
   return input(_lowerCAmelCase	).strip().split(" "	)

def      __snake_case						(					_lowerCAmelCase : int				,				_lowerCAmelCase : int	) ->						dict[int, list[int]]:
   A_					:				dict[int, list[int]]          =			{}
   for i in range(_lowerCAmelCase	):
      A_					:				Tuple          =			[]

   for e in range(_lowerCAmelCase	):
      A_      ,						A_					:				Optional[Any]          =			(int(_lowerCAmelCase	) for i in _input(f"Edge {e + 1}: <node1> <node2> "	))
      graph[x].append(_lowerCAmelCase	)
   return graph

def      __snake_case						(					_lowerCAmelCase : int				,				_lowerCAmelCase : int	) ->						dict[int, list[int]]:
   A_					:				dict[int, list[int]]          =			{}
   for i in range(_lowerCAmelCase	):
      A_					:				Dict          =			[]

   for e in range(_lowerCAmelCase	):
      A_      ,						A_					:				str          =			(int(_lowerCAmelCase	) for i in _input(f"Edge {e + 1}: <node1> <node2> "	))
      graph[x].append(_lowerCAmelCase	)
      graph[y].append(_lowerCAmelCase	)
   return graph

def      __snake_case						(					_lowerCAmelCase : int				,				_lowerCAmelCase : int	) ->						dict[int, list[tuple[int, int]]]:
   A_					:				dict[int, list[tuple[int, int]]]          =			{}
   for i in range(_lowerCAmelCase	):
      A_					:				Tuple          =			[]

   for e in range(_lowerCAmelCase	):
      A_      ,						A_      ,						A_					:				int          =			(int(_lowerCAmelCase	) 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__":
 _lowerCAmelCase					,					_lowerCAmelCase							:      Optional[int]						=	(int(i) for i in _input('''Number of nodes and edges: '''))

 _lowerCAmelCase							:      Dict						=	int(
     _input(
         '''Press 1 or 2 or 3 \n'''
         '''1. Unweighted directed \n'''
         '''2. Unweighted undirected \n'''
         '''3. Weighted undirected \n'''
     )[0]
 )

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

def      __snake_case						(					_lowerCAmelCase : Dict				,				_lowerCAmelCase : Optional[Any]	) ->						Tuple:
   A_      ,						A_					:				Any          =			{s}, [s]
   print(_lowerCAmelCase	)
   while _s:
      A_					:				Optional[Any]          =			0
      for i in g[_s[-1]]:
         if i not in vis:
            _s.append(_lowerCAmelCase	)
            vis.add(_lowerCAmelCase	)
            A_					:				str          =			1
            print(_lowerCAmelCase	)
            break
      if not flag:
         _s.pop()

def      __snake_case						(					_lowerCAmelCase : Optional[Any]				,				_lowerCAmelCase : List[str]	) ->						List[Any]:
   A_      ,						A_					:				int          =			{s}, deque([s]	)
   print(_lowerCAmelCase	)
   while q:
      A_					:				str          =			q.popleft()
      for v in g[u]:
         if v not in vis:
            vis.add(_lowerCAmelCase	)
            q.append(_lowerCAmelCase	)
            print(_lowerCAmelCase	)

def      __snake_case						(					_lowerCAmelCase : Tuple				,				_lowerCAmelCase : Any	) ->						Optional[int]:
   A_      ,						A_      ,						A_					:				Tuple          =			{s: 0}, set(), {s: 0}
   while True:
      if len(_lowerCAmelCase	) == len(_lowerCAmelCase	) - 1:
         break
      A_					:				List[Any]          =			100000
      for i in dist:
         if i not in known and dist[i] < mini:
            A_					:				Optional[Any]          =			dist[i]
            A_					:				List[str]          =			i
      known.add(_lowerCAmelCase	)
      for v in g[u]:
         if v[0] not in known and dist[u] + v[1] < dist.get(v[0]				,				100000	):
            A_					:				List[Any]          =			dist[u] + v[1]
            A_					:				int          =			u
   for i in dist:
      if i != s:
         print(dist[i]	)

def      __snake_case						(					_lowerCAmelCase : Any				,				_lowerCAmelCase : Any=None				,				_lowerCAmelCase : str=None	) ->						Optional[Any]:
   if q is None:
      A_					:				Optional[Any]          =			[1]
   if ind is None:
      A_					:				List[Any]          =			[0] * (len(_lowerCAmelCase	) + 1)  # SInce oth Index is ignored
      for u in g:
         for v in g[u]:
            ind[v] += 1
      A_					:				List[str]          =			deque()
      for i in g:
         if ind[i] == 0:
            q.append(_lowerCAmelCase	)
   if len(_lowerCAmelCase	) == 0:
      return
   A_					:				Optional[Any]          =			q.popleft()
   print(_lowerCAmelCase	)
   for w in g[v]:
      ind[w] -= 1
      if ind[w] == 0:
         q.append(_lowerCAmelCase	)
   topo(_lowerCAmelCase				,				_lowerCAmelCase				,				_lowerCAmelCase	)

def      __snake_case						(					) ->						Tuple:
   A_					:				Union[str, Any]          =			input().strip()
   A_					:				Optional[Any]          =			[]
   for _ in range(_lowerCAmelCase	):
      a.append(map(_lowerCAmelCase				,				input().strip().split()	)	)
   return a, n

def      __snake_case						(					_lowerCAmelCase : Dict	) ->						Optional[Any]:
   ((A_)      ,						(A_))					:				Optional[int]          =			a_and_n
   A_					:				Tuple          =			list(_lowerCAmelCase	)
   A_					:				List[str]          =			[[0] * n for i in range(_lowerCAmelCase	)]
   for k in range(_lowerCAmelCase	):
      for i in range(_lowerCAmelCase	):
         for j in range(_lowerCAmelCase	):
            if dist[i][j] > dist[i][k] + dist[k][j]:
               A_					:				Optional[Any]          =			dist[i][k] + dist[k][j]
               A_					:				Optional[int]          =			k
   print(_lowerCAmelCase	)

def      __snake_case						(					_lowerCAmelCase : Dict				,				_lowerCAmelCase : int	) ->						Optional[int]:
   A_      ,						A_      ,						A_					:				Dict          =			{s: 0}, set(), {s: 0}
   while True:
      if len(_lowerCAmelCase	) == len(_lowerCAmelCase	) - 1:
         break
      A_					:				Union[str, Any]          =			100000
      for i in dist:
         if i not in known and dist[i] < mini:
            A_					:				Tuple          =			dist[i]
            A_					:				Dict          =			i
      known.add(_lowerCAmelCase	)
      for v in g[u]:
         if v[0] not in known and v[1] < dist.get(v[0]				,				100000	):
            A_					:				Optional[Any]          =			v[1]
            A_					:				List[Any]          =			u
   return dist

def      __snake_case						(					) ->						str:
   A_      ,						A_					:				str          =			map(_lowerCAmelCase				,				input().split(" "	)	)
   A_					:				Any          =			[]
   for _ in range(_lowerCAmelCase	):
      edges.append(map(_lowerCAmelCase				,				input().split(" "	)	)	)
   return edges, n

def      __snake_case						(					_lowerCAmelCase : List[Any]	) ->						List[Any]:
   # Sort edges on the basis of distance
   ((A_)      ,						(A_))					:				str          =			e_and_n
   e.sort(reverse=_lowerCAmelCase				,				key=lambda _lowerCAmelCase	: x[2]	)
   A_					:				int          =			[{i} for i in range(1				,				n + 1	)]
   while True:
      if len(_lowerCAmelCase	) == 1:
         break
      print(_lowerCAmelCase	)
      A_					:				List[Any]          =			e.pop()
      for i in range(len(_lowerCAmelCase	)	):
         if x[0] in s[i]:
            break
      for j in range(len(_lowerCAmelCase	)	):
         if x[1] in s[j]:
            if i == j:
               break
            s[j].update(s[i]	)
            s.pop(_lowerCAmelCase	)
            break





def      __snake_case						(					_lowerCAmelCase : Dict	) ->						Union[str, Any]:
   A_					:				Dict          =			[]
   for node in graph:
      if not graph[node]:
         isolated.append(_lowerCAmelCase	)
   return isolated







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, prepare_image_inputs


if is_torch_available():
 import torch

if is_vision_available():
 from PIL import Image

 from transformers import ViltImageProcessor


class 					__magic_name__  (							unittest.TestCase							):





     """simple docstring"""



     def __init__(							self       :Dict			,      snake_case       :str			,      snake_case       :Tuple=7			,      snake_case       :Union[str, Any]=3			,      snake_case       :Any=18			,      snake_case       :Tuple=30			,      snake_case       :List[str]=400			,      snake_case       :Optional[Any]=True			,      snake_case       :Optional[int]=None			,      snake_case       :str=2			,      snake_case       :Tuple=True			,      snake_case       :List[str]=[0.5, 0.5, 0.5]			,      snake_case       :int=[0.5, 0.5, 0.5]			,      ):





        '''simple docstring'''




        A_					:				Optional[Any]          =			size if size is not None else {"shortest_edge": 30}
        A_					:				Tuple          =			parent
        A_					:				Tuple          =			batch_size
        A_					:				Any          =			num_channels
        A_					:				Dict          =			image_size
        A_					:				int          =			min_resolution
        A_					:				Optional[Any]          =			max_resolution
        A_					:				Union[str, Any]          =			do_resize
        A_					:				List[Any]          =			size
        A_					:				List[str]          =			size_divisor
        A_					:				str          =			do_normalize
        A_					:				int          =			image_mean
        A_					:				str          =			image_std



     def 						SCREAMING_SNAKE_CASE		(							self       :List[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,
            "size_divisor": self.size_divisor,
        }





     def 						SCREAMING_SNAKE_CASE		(							self       :Optional[Any]			,      snake_case       :Tuple			,      snake_case       :List[str]=False  ):





        '''simple docstring'''




        if not batched:
           A_					:				List[Any]          =			self.size["shortest_edge"]
           A_					:				Tuple          =			image_inputs[0]
           if isinstance(snake_case			,      Image.Image  ):
              A_      ,						A_					:				str          =			image.size
           else:
              A_      ,						A_					:				Optional[int]          =			image.shape[1], image.shape[2]
           A_					:				int          =			size / min(snake_case			,      snake_case  )
           if h < w:
              A_      ,						A_					:				Dict          =			size, scale * w
           else:
              A_      ,						A_					:				Tuple          =			scale * h, size

           A_					:				List[Any]          =			int((1_333 / 800) * size  )
           if max(snake_case			,      snake_case  ) > max_size:
              A_					:				Union[str, Any]          =			max_size / max(snake_case			,      snake_case  )
              A_					:				Tuple          =			newh * scale
              A_					:				List[str]          =			neww * scale

           A_      ,						A_					:				Optional[int]          =			int(newh + 0.5  ), int(neww + 0.5  )
           A_      ,						A_					:				Tuple          =			(
               newh // self.size_divisor * self.size_divisor,
               neww // self.size_divisor * self.size_divisor,
           )

        else:
           A_					:				List[Any]          =			[]
           for image in image_inputs:
              A_      ,						A_					:				str          =			self.get_expected_values([image]  )
              expected_values.append((expected_height, expected_width)  )
           A_					:				Optional[Any]          =			max(snake_case			,      key=lambda snake_case  : item[0]  )[0]
           A_					:				Optional[int]          =			max(snake_case			,      key=lambda snake_case  : item[1]  )[1]

        return expected_height, expected_width




@require_torch
@require_vision
class 					__magic_name__  (							lowerCamelCase__    ,				unittest.TestCase							):





     """simple docstring"""



     __UpperCamelCase					    =     ViltImageProcessor if is_vision_available() else None



     def 						SCREAMING_SNAKE_CASE		(							self       :Union[str, Any]  ):





        '''simple docstring'''




        A_					:				Dict          =			ViltImageProcessingTester(self  )



     @property
     def 						SCREAMING_SNAKE_CASE		(							self       :Union[str, Any]  ):





        '''simple docstring'''




        return self.image_processor_tester.prepare_image_processor_dict()



     def 						SCREAMING_SNAKE_CASE		(							self       :List[Any]  ):





        '''simple docstring'''




        A_					:				Optional[int]          =			self.image_processing_class(**self.image_processor_dict  )
        self.assertTrue(hasattr(snake_case			,      "image_mean"  )  )
        self.assertTrue(hasattr(snake_case			,      "image_std"  )  )
        self.assertTrue(hasattr(snake_case			,      "do_normalize"  )  )
        self.assertTrue(hasattr(snake_case			,      "do_resize"  )  )
        self.assertTrue(hasattr(snake_case			,      "size"  )  )
        self.assertTrue(hasattr(snake_case			,      "size_divisor"  )  )



     def 						SCREAMING_SNAKE_CASE		(							self       :Tuple  ):





        '''simple docstring'''




        A_					:				Tuple          =			self.image_processing_class.from_dict(self.image_processor_dict  )
        self.assertEqual(image_processor.size			,      {"shortest_edge": 30}  )

        A_					:				Any          =			self.image_processing_class.from_dict(self.image_processor_dict			,      size=42  )
        self.assertEqual(image_processor.size			,      {"shortest_edge": 42}  )



     def 						SCREAMING_SNAKE_CASE		(							self       :List[str]  ):





        '''simple docstring'''




        pass



     def 						SCREAMING_SNAKE_CASE		(							self       :Optional[int]  ):





        '''simple docstring'''




        A_					:				Dict          =			self.image_processing_class(**self.image_processor_dict  )
        # create random PIL images
        A_					:				str          =			prepare_image_inputs(self.image_processor_tester			,      equal_resolution=snake_case  )
        for image in image_inputs:
           self.assertIsInstance(snake_case			,      Image.Image  )

        # Test not batched input
        A_					:				Optional[Any]          =			image_processing(image_inputs[0]			,      return_tensors="pt"  ).pixel_values

        A_      ,						A_					:				str          =			self.image_processor_tester.get_expected_values(snake_case  )
        self.assertEqual(
            encoded_images.shape			,      (1, self.image_processor_tester.num_channels, expected_height, expected_width)			,      )

        # Test batched
        A_					:				int          =			image_processing(snake_case			,      return_tensors="pt"  ).pixel_values

        A_      ,						A_					:				Dict          =			self.image_processor_tester.get_expected_values(snake_case			,      batched=snake_case  )
        self.assertEqual(
            encoded_images.shape			,      (
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                expected_height,
                expected_width,
            )			,      )



     def 						SCREAMING_SNAKE_CASE		(							self       :Optional[Any]  ):





        '''simple docstring'''




        A_					:				Any          =			self.image_processing_class(**self.image_processor_dict  )
        # create random numpy tensors
        A_					:				List[str]          =			prepare_image_inputs(self.image_processor_tester			,      equal_resolution=snake_case			,      numpify=snake_case  )
        for image in image_inputs:
           self.assertIsInstance(snake_case			,      np.ndarray  )

        # Test not batched input
        A_					:				List[Any]          =			image_processing(image_inputs[0]			,      return_tensors="pt"  ).pixel_values

        A_      ,						A_					:				int          =			self.image_processor_tester.get_expected_values(snake_case  )
        self.assertEqual(
            encoded_images.shape			,      (1, self.image_processor_tester.num_channels, expected_height, expected_width)			,      )

        # Test batched
        A_					:				Dict          =			image_processing(snake_case			,      return_tensors="pt"  ).pixel_values

        A_      ,						A_					:				str          =			self.image_processor_tester.get_expected_values(snake_case			,      batched=snake_case  )
        self.assertEqual(
            encoded_images.shape			,      (
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                expected_height,
                expected_width,
            )			,      )





     def 						SCREAMING_SNAKE_CASE		(							self       :str  ):





        '''simple docstring'''




        A_					:				Any          =			self.image_processing_class(**self.image_processor_dict  )
        # create random PyTorch tensors
        A_					:				Optional[Any]          =			prepare_image_inputs(self.image_processor_tester			,      equal_resolution=snake_case			,      torchify=snake_case  )
        for image in image_inputs:
           self.assertIsInstance(snake_case			,      torch.Tensor  )

        # Test not batched input
        A_					:				int          =			image_processing(image_inputs[0]			,      return_tensors="pt"  ).pixel_values

        A_      ,						A_					:				Union[str, Any]          =			self.image_processor_tester.get_expected_values(snake_case  )
        self.assertEqual(
            encoded_images.shape			,      (1, self.image_processor_tester.num_channels, expected_height, expected_width)			,      )

        # Test batched
        A_					:				List[str]          =			image_processing(snake_case			,      return_tensors="pt"  ).pixel_values

        A_      ,						A_					:				Optional[int]          =			self.image_processor_tester.get_expected_values(snake_case			,      batched=snake_case  )
        self.assertEqual(
            encoded_images.shape			,      (
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_channels,
                expected_height,
                expected_width,
            )			,      )
