import torch

from diffusers import EulerAncestralDiscreteScheduler
from diffusers.utils import torch_device

from .test_schedulers import SchedulerCommonTest
class        a_				(		SCREAMING_SNAKE_CASE		):






 '''simple docstring'''






 UpperCAmelCase_							=      (EulerAncestralDiscreteScheduler,)
 UpperCAmelCase_							=      10




 def 	__snake_case		(    self      :						List[str]    ,					**lowercase__      :						int):







        '''simple docstring'''



        lowerCAmelCase__  			=      {
            'num_train_timesteps': 1_100,
            'beta_start': 0.0_001,
            'beta_end': 0.02,
            'beta_schedule': 'linear',
        }

        config.update(**lowercase__)
        return config




 def 	__snake_case		(    self      :						Optional[int]):







        '''simple docstring'''



        for timesteps in [10, 50, 100, 1_000]:
               self.check_over_configs(num_train_timesteps=lowercase__)




 def 	__snake_case		(    self      :						int):







        '''simple docstring'''



        for beta_start, beta_end in zip([0.00_001, 0.0_001, 0.001]    ,					[0.0_002, 0.002, 0.02]):
               self.check_over_configs(beta_start=lowercase__    ,					beta_end=lowercase__)




 def 	__snake_case		(    self      :						Any):







        '''simple docstring'''



        for schedule in ["linear", "scaled_linear"]:
               self.check_over_configs(beta_schedule=lowercase__)




 def 	__snake_case		(    self      :						int):







        '''simple docstring'''



        for prediction_type in ["epsilon", "v_prediction"]:
               self.check_over_configs(prediction_type=lowercase__)




 def 	__snake_case		(    self      :						Any):







        '''simple docstring'''



        lowerCAmelCase__  			=      self.scheduler_classes[0]
        lowerCAmelCase__  			=      self.get_scheduler_config()
        lowerCAmelCase__  			=      scheduler_class(**lowercase__)

        scheduler.set_timesteps(self.num_inference_steps)

        lowerCAmelCase__  			=      torch.manual_seed(0)

        lowerCAmelCase__  			=      self.dummy_model()
        lowerCAmelCase__  			=      self.dummy_sample_deter * scheduler.init_noise_sigma.cpu()
        lowerCAmelCase__  			=      sample.to(lowercase__)

        for i, t in enumerate(scheduler.timesteps):
               lowerCAmelCase__  			=      scheduler.scale_model_input(lowercase__    ,					lowercase__)

               lowerCAmelCase__  			=      model(lowercase__    ,					lowercase__)

               lowerCAmelCase__  			=      scheduler.step(lowercase__    ,					lowercase__    ,					lowercase__    ,					generator=lowercase__)
               lowerCAmelCase__  			=      output.prev_sample

        lowerCAmelCase__  			=      torch.sum(torch.abs(lowercase__))
        lowerCAmelCase__  			=      torch.mean(torch.abs(lowercase__))

        assert abs(result_sum.item() - 152.3_192) < 1e-2
        assert abs(result_mean.item() - 0.1_983) < 1e-3




 def 	__snake_case		(    self      :						Any):







        '''simple docstring'''



        lowerCAmelCase__  			=      self.scheduler_classes[0]
        lowerCAmelCase__  			=      self.get_scheduler_config(prediction_type='v_prediction')
        lowerCAmelCase__  			=      scheduler_class(**lowercase__)

        scheduler.set_timesteps(self.num_inference_steps)

        lowerCAmelCase__  			=      torch.manual_seed(0)

        lowerCAmelCase__  			=      self.dummy_model()
        lowerCAmelCase__  			=      self.dummy_sample_deter * scheduler.init_noise_sigma
        lowerCAmelCase__  			=      sample.to(lowercase__)

        for i, t in enumerate(scheduler.timesteps):
               lowerCAmelCase__  			=      scheduler.scale_model_input(lowercase__    ,					lowercase__)

               lowerCAmelCase__  			=      model(lowercase__    ,					lowercase__)

               lowerCAmelCase__  			=      scheduler.step(lowercase__    ,					lowercase__    ,					lowercase__    ,					generator=lowercase__)
               lowerCAmelCase__  			=      output.prev_sample

        lowerCAmelCase__  			=      torch.sum(torch.abs(lowercase__))
        lowerCAmelCase__  			=      torch.mean(torch.abs(lowercase__))

        assert abs(result_sum.item() - 108.4_439) < 1e-2
        assert abs(result_mean.item() - 0.1_412) < 1e-3




 def 	__snake_case		(    self      :						List[Any]):







        '''simple docstring'''



        lowerCAmelCase__  			=      self.scheduler_classes[0]
        lowerCAmelCase__  			=      self.get_scheduler_config()
        lowerCAmelCase__  			=      scheduler_class(**lowercase__)

        scheduler.set_timesteps(self.num_inference_steps    ,					device=lowercase__)
        lowerCAmelCase__  			=      torch.manual_seed(0)

        lowerCAmelCase__  			=      self.dummy_model()
        lowerCAmelCase__  			=      self.dummy_sample_deter * scheduler.init_noise_sigma.cpu()
        lowerCAmelCase__  			=      sample.to(lowercase__)

        for t in scheduler.timesteps:
               lowerCAmelCase__  			=      scheduler.scale_model_input(lowercase__    ,					lowercase__)

               lowerCAmelCase__  			=      model(lowercase__    ,					lowercase__)

               lowerCAmelCase__  			=      scheduler.step(lowercase__    ,					lowercase__    ,					lowercase__    ,					generator=lowercase__)
               lowerCAmelCase__  			=      output.prev_sample

        lowerCAmelCase__  			=      torch.sum(torch.abs(lowercase__))
        lowerCAmelCase__  			=      torch.mean(torch.abs(lowercase__))

        assert abs(result_sum.item() - 152.3_192) < 1e-2
        assert abs(result_mean.item() - 0.1_983) < 1e-3

from __future__ import annotations






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






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






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


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

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

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