
'''simple docstring'''





import unittest

from transformers import (
    MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
    TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
    PreTrainedTokenizer,
    is_vision_available,
)
from transformers.pipelines import ImageClassificationPipeline, pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_torch_or_tf,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
 from PIL import Image
else:


 class 	UpperCamelCase__					:






  @staticmethod
  def 		lowercase_  (     *_A					:List[str]		,			**_A					:Union[str, Any]     )			->     Optional[Any]:







        '''simple docstring'''



        pass


@is_pipeline_test
@require_torch_or_tf
@require_vision
class 	UpperCamelCase__					(      unittest.TestCase):
 UpperCAmelCase__      :      Any  			=   MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
 UpperCAmelCase__      :      Optional[Any]  			=   TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING






 def 		lowercase_  (     self					:Union[str, Any]		,			_A					:Dict		,			_A					:List[Any]		,			_A					:Any     )			->     int:







       '''simple docstring'''



       __A    		=     ImageClassificationPipeline(model=_A		,			image_processor=_A		,			top_k=2     )
       __A    		=     [
           Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'     ),
           'http://images.cocodataset.org/val2017/000000039769.jpg',
       ]
       return image_classifier, examples






 def 		lowercase_  (     self					:Tuple		,			_A					:Tuple		,			_A					:Any     )			->     Any:







       '''simple docstring'''



       __A    		=     image_classifier('./tests/fixtures/tests_samples/COCO/000000039769.png'     )

       self.assertEqual(
           _A		,			[
               {'score': ANY(_A     ), 'label': ANY(_A     )},
               {'score': ANY(_A     ), 'label': ANY(_A     )},
           ]		,			)

       import datasets

       __A    		=     datasets.load_dataset('hf-internal-testing/fixtures_image_utils'		,			'image'		,			split='test'     )

       # Accepts URL + PIL.Image + lists
       __A    		=     image_classifier(
           [
               Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'     ),
               'http://images.cocodataset.org/val2017/000000039769.jpg',
               # RGBA
               dataset[0]['file'],
               # LA
               dataset[1]['file'],
               # L
               dataset[2]['file'],
           ]     )
       self.assertEqual(
           _A		,			[
               [
                   {'score': ANY(_A     ), 'label': ANY(_A     )},
                   {'score': ANY(_A     ), 'label': ANY(_A     )},
               ],
               [
                   {'score': ANY(_A     ), 'label': ANY(_A     )},
                   {'score': ANY(_A     ), 'label': ANY(_A     )},
               ],
               [
                   {'score': ANY(_A     ), 'label': ANY(_A     )},
                   {'score': ANY(_A     ), 'label': ANY(_A     )},
               ],
               [
                   {'score': ANY(_A     ), 'label': ANY(_A     )},
                   {'score': ANY(_A     ), 'label': ANY(_A     )},
               ],
               [
                   {'score': ANY(_A     ), 'label': ANY(_A     )},
                   {'score': ANY(_A     ), 'label': ANY(_A     )},
               ],
           ]		,			)






 @require_torch
 def 		lowercase_  (     self					:int     )			->     Dict:







       '''simple docstring'''



       __A    		=     'hf-internal-testing/tiny-random-vit'
       __A    		=     pipeline('image-classification'		,			model=_A     )

       __A    		=     image_classifier('http://images.cocodataset.org/val2017/000000039769.jpg'     )
       self.assertEqual(
           nested_simplify(_A		,			decimals=4     )		,			[{'label': 'LABEL_1', 'score': 0.574}, {'label': 'LABEL_0', 'score': 0.426}]		,			)

       __A    		=     image_classifier(
           [
               'http://images.cocodataset.org/val2017/000000039769.jpg',
               'http://images.cocodataset.org/val2017/000000039769.jpg',
           ]		,			top_k=2		,			)
       self.assertEqual(
           nested_simplify(_A		,			decimals=4     )		,			[
               [{'label': 'LABEL_1', 'score': 0.574}, {'label': 'LABEL_0', 'score': 0.426}],
               [{'label': 'LABEL_1', 'score': 0.574}, {'label': 'LABEL_0', 'score': 0.426}],
           ]		,			)






 @require_tf
 def 		lowercase_  (     self					:Dict     )			->     Dict:







       '''simple docstring'''



       __A    		=     'hf-internal-testing/tiny-random-vit'
       __A    		=     pipeline('image-classification'		,			model=_A		,			framework='tf'     )

       __A    		=     image_classifier('http://images.cocodataset.org/val2017/000000039769.jpg'     )
       self.assertEqual(
           nested_simplify(_A		,			decimals=4     )		,			[{'label': 'LABEL_1', 'score': 0.574}, {'label': 'LABEL_0', 'score': 0.426}]		,			)

       __A    		=     image_classifier(
           [
               'http://images.cocodataset.org/val2017/000000039769.jpg',
               'http://images.cocodataset.org/val2017/000000039769.jpg',
           ]		,			top_k=2		,			)
       self.assertEqual(
           nested_simplify(_A		,			decimals=4     )		,			[
               [{'label': 'LABEL_1', 'score': 0.574}, {'label': 'LABEL_0', 'score': 0.426}],
               [{'label': 'LABEL_1', 'score': 0.574}, {'label': 'LABEL_0', 'score': 0.426}],
           ]		,			)






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







       '''simple docstring'''



       __A    		=     PreTrainedTokenizer()

       # Assert that the pipeline can be initialized with a feature extractor that is not in any mapping
       __A    		=     pipeline(
           'image-classification'		,			model='hf-internal-testing/tiny-random-vit'		,			tokenizer=_A     )

       self.assertIs(image_classifier.tokenizer		,			_A     )






 @slow
 @require_torch
 def 		lowercase_  (     self					:int     )			->     Union[str, Any]:







       '''simple docstring'''



       __A    		=     pipeline('image-classification'		,			model='deepmind/vision-perceiver-conv'     )
       __A    		=     image_classifier('http://images.cocodataset.org/val2017/000000039769.jpg'     )
       self.assertEqual(
           nested_simplify(_A		,			decimals=4     )		,			[
               {'score': 0.4_385, 'label': 'tabby, tabby cat'},
               {'score': 0.321, 'label': 'tiger cat'},
               {'score': 0.0_502, 'label': 'Egyptian cat'},
               {'score': 0.0_137, 'label': 'crib, cot'},
               {'score': 0.007, 'label': 'radiator'},
           ]		,			)

       __A    		=     pipeline('image-classification'		,			model='deepmind/vision-perceiver-fourier'     )
       __A    		=     image_classifier('http://images.cocodataset.org/val2017/000000039769.jpg'     )
       self.assertEqual(
           nested_simplify(_A		,			decimals=4     )		,			[
               {'score': 0.5_658, 'label': 'tabby, tabby cat'},
               {'score': 0.1_309, 'label': 'tiger cat'},
               {'score': 0.0_722, 'label': 'Egyptian cat'},
               {'score': 0.0_707, 'label': 'remote control, remote'},
               {'score': 0.0_082, 'label': 'computer keyboard, keypad'},
           ]		,			)

       __A    		=     pipeline('image-classification'		,			model='deepmind/vision-perceiver-learned'     )
       __A    		=     image_classifier('http://images.cocodataset.org/val2017/000000039769.jpg'     )
       self.assertEqual(
           nested_simplify(_A		,			decimals=4     )		,			[
               {'score': 0.3_022, 'label': 'tabby, tabby cat'},
               {'score': 0.2_362, 'label': 'Egyptian cat'},
               {'score': 0.1_856, 'label': 'tiger cat'},
               {'score': 0.0_324, 'label': 'remote control, remote'},
               {'score': 0.0_096, 'label': 'quilt, comforter, comfort, puff'},
           ]		,			)








'''simple docstring'''





from __future__ import annotations





def     snake_case							(						UpperCAmelCase		)->     List[Any]:







      """simple docstring"""
      global graph, reversed_graph, scc, component, visit, stack
      if visit[u]:
            return
      __A    		=     True
      for v in graph[u]:
            dfs(UpperCAmelCase		)
      stack.append(UpperCAmelCase		)





def     snake_case							(						UpperCAmelCase		)->     List[Any]:







      """simple docstring"""
      global graph, reversed_graph, scc, component, visit, stack
      if visit[u]:
            return
      __A    		=     True
      component.append(UpperCAmelCase		)
      for v in reversed_graph[u]:
            dfsa(UpperCAmelCase		)





def     snake_case							(						)->     Any:







      """simple docstring"""
      global graph, reversed_graph, scc, component, visit, stack
      for i in range(UpperCAmelCase		):
            dfs(UpperCAmelCase		)
      __A    		=     [False] * n
      for i in stack[::-1]:
            if visit[i]:
                  continue
            __A    		=     []
            dfsa(UpperCAmelCase		)
            scc.append(UpperCAmelCase		)
      return scc


if __name__ == "__main__":
 # n - no of nodes, m - no of edges
 a__    ,						a__						:				Tuple           =    list(map(int, input().strip().split()))

 a__						:				list[list[int]]           =    [[] for _ in range(n)]  # graph
 a__						:				list[list[int]]           =    [[] for i in range(n)]  # reversed graph
 # input graph data (edges)
 for _ in range(m):
  a__    ,						a__						:				Tuple           =    list(map(int, input().strip().split()))
  graph[u].append(v)
  reversed_graph[v].append(u)

 a__						:				list[int]           =    []
 a__						:				list[bool]           =    [False] * n
 a__						:				list[int]           =    []
 a__						:				list[int]           =    []
 print(kosaraju())






