





from collections import deque




def 						A_			(  lowercase_  )			->						str:
       return input(lowercase_  ).strip().split(''' '''  )




def 						A_			(  lowercase_      ,		lowercase_  )			->						dict[int, list[int]]:
       _snake_case      :							dict[int, list[int]]     				=						{}
       for i in range(lowercase_  ):
              _snake_case      :							Union[str, Any]     				=						[]

       for e in range(lowercase_  ):
              _snake_case				,    _snake_case      :							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]]:
       _snake_case      :							dict[int, list[int]]     				=						{}
       for i in range(lowercase_  ):
              _snake_case      :							Union[str, Any]     				=						[]

       for e in range(lowercase_  ):
              _snake_case				,    _snake_case      :							Tuple     				=						(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]]]:
       _snake_case      :							dict[int, list[tuple[int, int]]]     				=						{}
       for i in range(lowercase_  ):
              _snake_case      :							Dict     				=						[]

       for e in range(lowercase_  ):
              _snake_case				,    _snake_case				,    _snake_case      :							str     				=						(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__":
   lowerCAmelCase_ ,    lowerCAmelCase_   =   (int(i) for i in _input("Number of nodes and edges: "))

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

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




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




def 						A_			(  lowercase_      ,		lowercase_  )			->						str:
       _snake_case				,    _snake_case      :							List[str]     				=						{s}, deque([s]  )
       print(lowercase_  )
       while q:
              _snake_case      :							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_  )			->						List[Any]:
       _snake_case				,    _snake_case				,    _snake_case      :							Optional[int]     				=						{s: 0}, set(), {s: 0}
       while True:
              if len(lowercase_  ) == len(lowercase_  ) - 1:
                     break
              _snake_case      :							Optional[Any]     				=						100000
              for i in dist:
                     if i not in known and dist[i] < mini:
                            _snake_case      :							Optional[Any]     				=						dist[i]
                            _snake_case      :							Dict     				=						i
              known.add(lowercase_  )
              for v in g[u]:
                     if v[0] not in known and dist[u] + v[1] < dist.get(v[0]      ,		100000  ):
                            _snake_case      :							List[str]     				=						dist[u] + v[1]
                            _snake_case      :							List[Any]     				=						u
       for i in dist:
              if i != s:
                     print(dist[i]  )




def 						A_			(  lowercase_      ,		lowercase_=None      ,		lowercase_=None  )			->						Dict:
       if q is None:
              _snake_case      :							Optional[Any]     				=						[1]
       if ind is None:
              _snake_case      :							int     				=						[0] * (len(lowercase_  ) + 1)  # SInce oth Index is ignored
              for u in g:
                     for v in g[u]:
                            ind[v] += 1
              _snake_case      :							Optional[Any]     				=						deque()
              for i in g:
                     if ind[i] == 0:
                            q.append(lowercase_  )
       if len(lowercase_  ) == 0:
              return
       _snake_case      :							str     				=						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_			(  )			->						Any:
       _snake_case      :							List[Any]     				=						input().strip()
       _snake_case      :							Dict     				=						[]
       for _ in range(lowercase_  ):
              a.append(map(lowercase_      ,		input().strip().split()  )  )
       return a, n




def 						A_			(  lowercase_  )			->						int:
       ((_snake_case)				,    (_snake_case))      :							Any     				=						a_and_n
       _snake_case      :							List[Any]     				=						list(lowercase_  )
       _snake_case      :							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]:
                                   _snake_case      :							Tuple     				=						dist[i][k] + dist[k][j]
                                   _snake_case      :							str     				=						k
       print(lowercase_  )




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




def 						A_			(  )			->						Tuple:
       _snake_case				,    _snake_case      :							List[Any]     				=						map(lowercase_      ,		input().split(''' '''  )  )
       _snake_case      :							List[Any]     				=						[]
       for _ in range(lowercase_  ):
              edges.append(map(lowercase_      ,		input().split(''' '''  )  )  )
       return edges, n




def 						A_			(  lowercase_  )			->						str:
       # Sort edges on the basis of distance
       ((_snake_case)				,    (_snake_case))      :							List[str]     				=						e_and_n
       e.sort(reverse=lowercase_      ,		key=lambda lowercase_  : x[2]  )
       _snake_case      :							List[Any]     				=						[{i} for i in range(1      ,		n + 1  )]
       while True:
              if len(lowercase_  ) == 1:
                     break
              print(lowercase_  )
              _snake_case      :							Any     				=						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:
       _snake_case      :							List[Any]     				=						[]
       for node in graph:
              if not graph[node]:
                     isolated.append(lowercase_  )
       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 ConvNextImageProcessor

class 				A    (unittest.TestCase				):



      def __init__(					self     ,  lowercase_     ,  lowercase_=7     ,  lowercase_=3     ,  lowercase_=18     ,  lowercase_=30     ,  lowercase_=400     ,  lowercase_=True     ,  lowercase_=None     ,  lowercase_=0.875     ,  lowercase_=True     ,  lowercase_=[0.5, 0.5, 0.5]     ,  lowercase_=[0.5, 0.5, 0.5]     ,  )      ->   List[str]:



             '''simple docstring'''

             _snake_case      :							Tuple     				=						size if size is not None else {'''shortest_edge''': 20}
             _snake_case      :							List[Any]     				=						parent
             _snake_case      :							Optional[int]     				=						batch_size
             _snake_case      :							str     				=						num_channels
             _snake_case      :							Union[str, Any]     				=						image_size
             _snake_case      :							Optional[Any]     				=						min_resolution
             _snake_case      :							Union[str, Any]     				=						max_resolution
             _snake_case      :							Tuple     				=						do_resize
             _snake_case      :							List[Any]     				=						size
             _snake_case      :							Optional[int]     				=						crop_pct
             _snake_case      :							Any     				=						do_normalize
             _snake_case      :							Optional[int]     				=						image_mean
             _snake_case      :							Union[str, Any]     				=						image_std



      def    __a (					self					)      ->   str:



             '''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,
                 "crop_pct": self.crop_pct,
             }


@require_torch
@require_vision
class 				A    (__UpperCAmelCase       ,unittest.TestCase				):
      _SCREAMING_SNAKE_CASE					=							ConvNextImageProcessor if is_vision_available() else None



      def    __a (					self					)      ->   Dict:



             '''simple docstring'''

             _snake_case      :							List[Any]     				=						ConvNextImageProcessingTester(self					)



      @property
      def    __a (					self					)      ->   Dict:



             '''simple docstring'''

             return self.image_processor_tester.prepare_image_processor_dict()



      def    __a (					self					)      ->   str:



             '''simple docstring'''

             _snake_case      :							List[Any]     				=						self.image_processing_class(**self.image_processor_dict					)
             self.assertTrue(hasattr(lowercase_     ,  '''do_resize'''					)					)
             self.assertTrue(hasattr(lowercase_     ,  '''size'''					)					)
             self.assertTrue(hasattr(lowercase_     ,  '''crop_pct'''					)					)
             self.assertTrue(hasattr(lowercase_     ,  '''do_normalize'''					)					)
             self.assertTrue(hasattr(lowercase_     ,  '''image_mean'''					)					)
             self.assertTrue(hasattr(lowercase_     ,  '''image_std'''					)					)



      def    __a (					self					)      ->   List[Any]:



             '''simple docstring'''

             _snake_case      :							int     				=						self.image_processing_class.from_dict(self.image_processor_dict					)
             self.assertEqual(image_processor.size     ,  {'''shortest_edge''': 20}					)

             _snake_case      :							Tuple     				=						self.image_processing_class.from_dict(self.image_processor_dict     ,  size=42					)
             self.assertEqual(image_processor.size     ,  {'''shortest_edge''': 42}					)



      def    __a (					self					)      ->   List[Any]:



             '''simple docstring'''

             pass



      def    __a (					self					)      ->   int:



             '''simple docstring'''

             _snake_case      :							Tuple     				=						self.image_processing_class(**self.image_processor_dict					)
             # create random PIL images
             _snake_case      :							List[str]     				=						prepare_image_inputs(self.image_processor_tester     ,  equal_resolution=lowercase_					)
             for image in image_inputs:
                    self.assertIsInstance(lowercase_     ,  Image.Image					)

             # Test not batched input
             _snake_case      :							List[str]     				=						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['''shortest_edge'''],
                     self.image_processor_tester.size['''shortest_edge'''],
                 )     ,  )

             # Test batched
             _snake_case      :							int     				=						image_processing(lowercase_     ,  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['''shortest_edge'''],
                     self.image_processor_tester.size['''shortest_edge'''],
                 )     ,  )



      def    __a (					self					)      ->   Dict:



             '''simple docstring'''

             _snake_case      :							Tuple     				=						self.image_processing_class(**self.image_processor_dict					)
             # create random numpy tensors
             _snake_case      :							Tuple     				=						prepare_image_inputs(self.image_processor_tester     ,  equal_resolution=lowercase_     ,  numpify=lowercase_					)
             for image in image_inputs:
                    self.assertIsInstance(lowercase_     ,  np.ndarray					)

             # Test not batched input
             _snake_case      :							List[str]     				=						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['''shortest_edge'''],
                     self.image_processor_tester.size['''shortest_edge'''],
                 )     ,  )

             # Test batched
             _snake_case      :							Union[str, Any]     				=						image_processing(lowercase_     ,  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['''shortest_edge'''],
                     self.image_processor_tester.size['''shortest_edge'''],
                 )     ,  )



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



             '''simple docstring'''

             _snake_case      :							Union[str, Any]     				=						self.image_processing_class(**self.image_processor_dict					)
             # create random PyTorch tensors
             _snake_case      :							Dict     				=						prepare_image_inputs(self.image_processor_tester     ,  equal_resolution=lowercase_     ,  torchify=lowercase_					)
             for image in image_inputs:
                    self.assertIsInstance(lowercase_     ,  torch.Tensor					)

             # Test not batched input
             _snake_case      :							Union[str, Any]     				=						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['''shortest_edge'''],
                     self.image_processor_tester.size['''shortest_edge'''],
                 )     ,  )

             # Test batched
             _snake_case      :							List[Any]     				=						image_processing(lowercase_     ,  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['''shortest_edge'''],
                     self.image_processor_tester.size['''shortest_edge'''],
                 )     ,  )






