
"""simple docstring"""

import inspect
import unittest

from transformers import EfficientNetConfig
from transformers.testing_utils import is_pipeline_test, require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
   import torch

   from transformers import EfficientNetForImageClassification, EfficientNetModel
   from transformers.models.efficientnet.modeling_efficientnet import EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
   from PIL import Image

   from transformers import AutoImageProcessor
class    _UpperCAmelCase							:




      def __init__(							self      ,				lowercase_      ,				lowercase_=1_3      ,				lowercase_=3_2      ,				lowercase_=3      ,				lowercase_=[3, 3, 5]      ,				lowercase_=[3_2, 1_6, 2_4]      ,				lowercase_=[1_6, 2_4, 4_0]      ,				lowercase_=[1, 1, 2]      ,				lowercase_=[1, 1, 2]      ,				lowercase_=[1, 6, 6]      ,				lowercase_=True      ,				lowercase_=True      ,				lowercase_=3_7      ,				lowercase_="gelu"      ,				lowercase_=1_0      ,				)  ->    Tuple:
          UpperCAmelCase  	=    parent
          UpperCAmelCase  	=    batch_size
          UpperCAmelCase  	=    image_size
          UpperCAmelCase  	=    num_channels
          UpperCAmelCase  	=    kernel_sizes
          UpperCAmelCase  	=    in_channels
          UpperCAmelCase  	=    out_channels
          UpperCAmelCase  	=    strides
          UpperCAmelCase  	=    num_block_repeats
          UpperCAmelCase  	=    expand_ratios
          UpperCAmelCase  	=    is_training
          UpperCAmelCase  	=    hidden_act
          UpperCAmelCase  	=    num_labels
          UpperCAmelCase  	=    use_labels




      def 			a_					(							self							)  ->    Optional[int]:
          UpperCAmelCase  	=    floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]							)

          UpperCAmelCase  	=    None
          if self.use_labels:
              UpperCAmelCase  	=    ids_tensor([self.batch_size]      ,				self.num_labels							)

          UpperCAmelCase  	=    self.get_config()
          return config, pixel_values, labels




      def 			a_					(							self							)  ->    List[Any]:
          return EfficientNetConfig(
              num_channels=self.num_channels      ,				kernel_sizes=self.kernel_sizes      ,				in_channels=self.in_channels      ,				out_channels=self.out_channels      ,				strides=self.strides      ,				num_block_repeats=self.num_block_repeats      ,				expand_ratios=self.expand_ratios      ,				hidden_act=self.hidden_act      ,				num_labels=self.num_labels      ,				)




      def 			a_					(							self      ,				lowercase_      ,				lowercase_      ,				lowercase_							)  ->    Union[str, Any]:
          UpperCAmelCase  	=    EfficientNetModel(config=lowercase_							)
          model.to(lowercase_							)
          model.eval()
          UpperCAmelCase  	=    model(lowercase_							)
          # expected last hidden states: B, C, H // 4, W // 4
          self.parent.assertEqual(
              result.last_hidden_state.shape      ,				(self.batch_size, config.hidden_dim, self.image_size // 4, self.image_size // 4)      ,				)




      def 			a_					(							self      ,				lowercase_      ,				lowercase_      ,				lowercase_							)  ->    Any:
          UpperCAmelCase  	=    EfficientNetForImageClassification(lowercase_							)
          model.to(lowercase_							)
          model.eval()
          UpperCAmelCase  	=    model(lowercase_      ,				labels=lowercase_							)
          self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.num_labels)							)




      def 			a_					(							self							)  ->    int:
          UpperCAmelCase  	=    self.prepare_config_and_inputs()
          UpperCAmelCase	,							UpperCAmelCase	,							UpperCAmelCase  	=    config_and_inputs
          UpperCAmelCase  	=    {'pixel_values': pixel_values}
          return config, inputs_dict

@require_torch
class    _UpperCAmelCase							(						SCREAMING_SNAKE_CASE_   ,	SCREAMING_SNAKE_CASE_   ,	unittest.TestCase							):
      __SCREAMING_SNAKE_CASE      :							Union[str, Any]												=		(EfficientNetModel, EfficientNetForImageClassification) if is_torch_available() else ()
      __SCREAMING_SNAKE_CASE      :							Dict												=		(
          {"feature-extraction": EfficientNetModel, "image-classification": EfficientNetForImageClassification}
          if is_torch_available()
          else {}
      )

      __SCREAMING_SNAKE_CASE      :							List[str]												=		False
      __SCREAMING_SNAKE_CASE      :							Any												=		False
      __SCREAMING_SNAKE_CASE      :							Tuple												=		False
      __SCREAMING_SNAKE_CASE      :							List[Any]												=		False
      __SCREAMING_SNAKE_CASE      :							List[str]												=		False




      def 			a_					(							self							)  ->    str:
          UpperCAmelCase  	=    EfficientNetModelTester(self							)
          UpperCAmelCase  	=    ConfigTester(
              self      ,				config_class=lowercase_      ,				has_text_modality=lowercase_      ,				hidden_size=3_7							)




      def 			a_					(							self							)  ->    List[str]:
          self.create_and_test_config_common_properties()
          self.config_tester.create_and_test_config_to_json_string()
          self.config_tester.create_and_test_config_to_json_file()
          self.config_tester.create_and_test_config_from_and_save_pretrained()
          self.config_tester.create_and_test_config_with_num_labels()
          self.config_tester.check_config_can_be_init_without_params()
          self.config_tester.check_config_arguments_init()




      def 			a_					(							self							)  ->    Dict:
          return




      @unittest.skip(reason='EfficientNet does not use inputs_embeds'							)
      def 			a_					(							self							)  ->    Any:
          pass




      @unittest.skip(reason='EfficientNet does not support input and output embeddings'							)
      def 			a_					(							self							)  ->    List[Any]:
          pass




      @unittest.skip(reason='EfficientNet does not use feedforward chunking'							)
      def 			a_					(							self							)  ->    List[str]:
          pass




      def 			a_					(							self							)  ->    Tuple:
          UpperCAmelCase	,							UpperCAmelCase  	=    self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in self.all_model_classes:
              UpperCAmelCase  	=    model_class(lowercase_							)
              UpperCAmelCase  	=    inspect.signature(model.forward							)
              # signature.parameters is an OrderedDict => so arg_names order is deterministic
              UpperCAmelCase  	=    [*signature.parameters.keys()]

              UpperCAmelCase  	=    ['pixel_values']
              self.assertListEqual(arg_names[:1]      ,				lowercase_							)




      def 			a_					(							self							)  ->    Optional[int]:
          UpperCAmelCase  	=    self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*lowercase_							)




      def 			a_					(							self							)  ->    List[Any]:
          def check_hidden_states_output(lowercase_      ,				lowercase_      ,				lowercase_							):
              UpperCAmelCase  	=    model_class(lowercase_							)
              model.to(lowercase_							)
              model.eval()

              with torch.no_grad():
                  UpperCAmelCase  	=    model(**self._prepare_for_class(lowercase_      ,				lowercase_							)							)

              UpperCAmelCase  	=    outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states
              UpperCAmelCase  	=    sum(config.num_block_repeats							) * 4
              self.assertEqual(len(lowercase_							)      ,				lowercase_							)

              # EfficientNet's feature maps are of shape (batch_size, num_channels, height, width)
              self.assertListEqual(
                  list(hidden_states[0].shape[-2:]							)      ,				[self.model_tester.image_size // 2, self.model_tester.image_size // 2]      ,				)

          UpperCAmelCase	,							UpperCAmelCase  	=    self.model_tester.prepare_config_and_inputs_for_common()

          for model_class in self.all_model_classes:
              UpperCAmelCase  	=    True
              check_hidden_states_output(lowercase_      ,				lowercase_      ,				lowercase_							)

              # check that output_hidden_states also work using config
              del inputs_dict["output_hidden_states"]
              UpperCAmelCase  	=    True

              check_hidden_states_output(lowercase_      ,				lowercase_      ,				lowercase_							)




      def 			a_					(							self							)  ->    Optional[Any]:
          UpperCAmelCase  	=    self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_image_classification(*lowercase_							)




      @unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'							)
      def 			a_					(							self							)  ->    Any:
          pass




      @slow
      def 			a_					(							self							)  ->    int:
          for model_name in EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              UpperCAmelCase  	=    EfficientNetModel.from_pretrained(lowercase_							)
              self.assertIsNotNone(lowercase_							)




      @is_pipeline_test
      @require_vision
      @slow
      def 			a_					(							self							)  ->    Optional[Any]:
          super().test_pipeline_image_classification()




def 			lowercase__  (    )       ->					str:






    """simple docstring"""




    UpperCAmelCase  	=    Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'       )
    return image







@require_torch
@require_vision
class    _UpperCAmelCase							(						unittest.TestCase							):




      @cached_property
      def 			a_					(							self							)  ->    List[str]:
          return AutoImageProcessor.from_pretrained('google/efficientnet-b7'							) if is_vision_available() else None




      @slow
      def 			a_					(							self							)  ->    Tuple:
          UpperCAmelCase  	=    EfficientNetForImageClassification.from_pretrained('google/efficientnet-b7'							).to(lowercase_							)

          UpperCAmelCase  	=    self.default_image_processor
          UpperCAmelCase  	=    prepare_img()
          UpperCAmelCase  	=    image_processor(images=lowercase_      ,				return_tensors='pt'							).to(lowercase_							)

          # forward pass
          with torch.no_grad():
              UpperCAmelCase  	=    model(**lowercase_							)

          # verify the logits
          UpperCAmelCase  	=    torch.Size((1, 1_0_0_0)							)
          self.assertEqual(outputs.logits.shape      ,				lowercase_							)

          UpperCAmelCase  	=    torch.tensor([0.0_0_0_1, 0.0_0_0_2, 0.0_0_0_2]							).to(lowercase_							)
          self.assertTrue(torch.allclose(outputs.logits[0, :3]      ,				lowercase_      ,				atol=1E-4							)							)





"""simple docstring"""

from __future__ import annotations




def 			lowercase__  (    lowerCAmelCase :    Dict       )       ->					Optional[int]:






    """simple docstring"""




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




def 			lowercase__  (    lowerCAmelCase :    Optional[int]       )       ->					int:






    """simple docstring"""




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




def 			lowercase__  (    )       ->					List[str]:






    """simple docstring"""




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


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

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

   SCREAMING_SNAKE_CASE_			    =  []
   SCREAMING_SNAKE_CASE_			    =  [False] * n
   SCREAMING_SNAKE_CASE_			    =  []
   SCREAMING_SNAKE_CASE_			    =  []
   print(kosaraju())



