




"""simple docstring"""

import json
import os
import unittest

from transformers import AutoTokenizer, GPTaTokenizer, GPTaTokenizerFast
from transformers.models.gpta.tokenization_gpta import VOCAB_FILES_NAMES
from transformers.testing_utils import require_tokenizers

from ...test_tokenization_common import TokenizerTesterMixin

@require_tokenizers
class        lowercase      (    UpperCamelCase_     ,	unittest.TestCase):
    __lowerCAmelCase    :    Dict         =   GPTaTokenizer
    __lowerCAmelCase    :    Union[str, Any]         =   GPTaTokenizerFast
    __lowerCAmelCase    :    List[str]         =   True
    __lowerCAmelCase    :    Optional[int]         =   {"""add_prefix_space""": True}
    __lowerCAmelCase    :    Optional[Any]         =   False







    def 					a_  (							self   :					List[str]       ):



     """simple docstring"""

     super().setUp()

     # Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
     A_  :				List[str]	   =		[
         '''l''',
         '''o''',
         '''w''',
         '''e''',
         '''r''',
         '''s''',
         '''t''',
         '''i''',
         '''d''',
         '''n''',
         '''\u0120''',
         '''\u0120l''',
         '''\u0120n''',
         '''\u0120lo''',
         '''\u0120low''',
         '''er''',
         '''\u0120lowest''',
         '''\u0120newer''',
         '''\u0120wider''',
         '''<unk>''',
         '''<|endoftext|>''',
     ]
     A_  :				Tuple	   =		dict(zip(UpperCamelCase__      ,     range(len(UpperCamelCase__       )       )       )       )
     A_  :				Optional[Any]	   =		['''#version: 0.2''', '''\u0120 l''', '''\u0120l o''', '''\u0120lo w''', '''e r''', '''''']
     A_  :				int	   =		{'''unk_token''': '''<unk>'''}

     A_  :				int	   =		os.path.join(self.tmpdirname      ,     VOCAB_FILES_NAMES['''vocab_file''']       )
     A_  :				Union[str, Any]	   =		os.path.join(self.tmpdirname      ,     VOCAB_FILES_NAMES['''merges_file''']       )
     with open(self.vocab_file      ,     '''w'''      ,     encoding='''utf-8'''       ) as fp:
      fp.write(json.dumps(UpperCamelCase__       ) + '''\n'''       )
     with open(self.merges_file      ,     '''w'''      ,     encoding='''utf-8'''       ) as fp:
      fp.write('''\n'''.join(UpperCamelCase__       )       )







    def 					a_  (							self   :					Any      ,     **_lowerCamelCase   :					Dict       ):



     """simple docstring"""

     kwargs.update(self.special_tokens_map       )
     return GPTaTokenizer.from_pretrained(self.tmpdirname      ,     **UpperCamelCase__       )







    def 					a_  (							self   :					Optional[Any]      ,     **_lowerCamelCase   :					Any       ):



     """simple docstring"""

     kwargs.update(self.special_tokens_map       )
     return GPTaTokenizerFast.from_pretrained(self.tmpdirname      ,     **UpperCamelCase__       )







    def 					a_  (							self   :					str      ,     _lowerCamelCase   :					Dict       ):



     """simple docstring"""

     A_  :				str	   =		'''lower newer'''
     A_  :				List[str]	   =		'''lower newer'''
     return input_text, output_text







    def 					a_  (							self   :					int       ):



     """simple docstring"""

     A_  :				List[str]	   =		GPTaTokenizer(self.vocab_file      ,     self.merges_file      ,     **self.special_tokens_map       )
     A_  :				Optional[int]	   =		'''lower newer'''
     A_  :				str	   =		['''\u0120low''', '''er''', '''\u0120''', '''n''', '''e''', '''w''', '''er''']
     A_  :				Union[str, Any]	   =		tokenizer.tokenize(UpperCamelCase__      ,     add_prefix_space=UpperCamelCase__       )
     self.assertListEqual(UpperCamelCase__      ,     UpperCamelCase__       )

     A_  :				int	   =		tokens + [tokenizer.unk_token]
     A_  :				List[str]	   =		[14, 15, 10, 9, 3, 2, 15, 19]
     self.assertListEqual(tokenizer.convert_tokens_to_ids(UpperCamelCase__       )      ,     UpperCamelCase__       )







    def 					a_  (							self   :					str       ):



     """simple docstring"""

     if not self.test_rust_tokenizer:
      return

     A_  :				List[Any]	   =		self.get_tokenizer()
     A_  :				List[Any]	   =		self.get_rust_tokenizer(add_prefix_space=UpperCamelCase__       )

     A_  :				Dict	   =		'''lower newer'''

     # Testing tokenization
     A_  :				str	   =		tokenizer.tokenize(UpperCamelCase__      ,     add_prefix_space=UpperCamelCase__       )
     A_  :				Union[str, Any]	   =		rust_tokenizer.tokenize(UpperCamelCase__       )
     self.assertListEqual(UpperCamelCase__      ,     UpperCamelCase__       )

     # Testing conversion to ids without special tokens
     A_  :				Tuple	   =		tokenizer.encode(UpperCamelCase__      ,     add_special_tokens=UpperCamelCase__      ,     add_prefix_space=UpperCamelCase__       )
     A_  :				Any	   =		rust_tokenizer.encode(UpperCamelCase__      ,     add_special_tokens=UpperCamelCase__       )
     self.assertListEqual(UpperCamelCase__      ,     UpperCamelCase__       )

     # Testing conversion to ids with special tokens
     A_  :				List[Any]	   =		self.get_rust_tokenizer(add_prefix_space=UpperCamelCase__       )
     A_  :				List[Any]	   =		tokenizer.encode(UpperCamelCase__      ,     add_prefix_space=UpperCamelCase__       )
     A_  :				Optional[int]	   =		rust_tokenizer.encode(UpperCamelCase__       )
     self.assertListEqual(UpperCamelCase__      ,     UpperCamelCase__       )

     # Testing the unknown token
     A_  :				Union[str, Any]	   =		tokens + [rust_tokenizer.unk_token]
     A_  :				List[str]	   =		[14, 15, 10, 9, 3, 2, 15, 19]
     self.assertListEqual(rust_tokenizer.convert_tokens_to_ids(UpperCamelCase__       )      ,     UpperCamelCase__       )







    def 					a_  (							self   :					List[Any]      ,     *_lowerCamelCase   :					List[str]      ,     **_lowerCamelCase   :					int       ):



     """simple docstring"""

     pass







    def 					a_  (							self   :					Tuple      ,     _lowerCamelCase   :					Union[str, Any]=15       ):



     """simple docstring"""

     for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
      with self.subTest(F"""{tokenizer.__class__.__name__} ({pretrained_name})"""       ):
       A_  :				Dict	   =		self.rust_tokenizer_class.from_pretrained(UpperCamelCase__      ,     **UpperCamelCase__       )

       # Simple input
       A_  :				Union[str, Any]	   =		'''This is a simple input'''
       A_  :				Tuple	   =		['''This is a simple input 1''', '''This is a simple input 2''']
       A_  :				List[Any]	   =		('''This is a simple input''', '''This is a pair''')
       A_  :				Any	   =		[
           ('''This is a simple input 1''', '''This is a simple input 2'''),
           ('''This is a simple pair 1''', '''This is a simple pair 2'''),
       ]

       # Simple input tests
       self.assertRaises(UpperCamelCase__      ,     tokenizer_r.encode      ,     UpperCamelCase__      ,     max_length=UpperCamelCase__      ,     padding='''max_length'''       )

       # Simple input
       self.assertRaises(UpperCamelCase__      ,     tokenizer_r.encode_plus      ,     UpperCamelCase__      ,     max_length=UpperCamelCase__      ,     padding='''max_length'''       )

       # Simple input
       self.assertRaises(
           UpperCamelCase__      ,     tokenizer_r.batch_encode_plus      ,     UpperCamelCase__      ,     max_length=UpperCamelCase__      ,     padding='''max_length'''      ,     )

       # Pair input
       self.assertRaises(UpperCamelCase__      ,     tokenizer_r.encode      ,     UpperCamelCase__      ,     max_length=UpperCamelCase__      ,     padding='''max_length'''       )

       # Pair input
       self.assertRaises(UpperCamelCase__      ,     tokenizer_r.encode_plus      ,     UpperCamelCase__      ,     max_length=UpperCamelCase__      ,     padding='''max_length'''       )

       # Pair input
       self.assertRaises(
           UpperCamelCase__      ,     tokenizer_r.batch_encode_plus      ,     UpperCamelCase__      ,     max_length=UpperCamelCase__      ,     padding='''max_length'''      ,     )







    def 					a_  (							self   :					Tuple       ):



     """simple docstring"""

     A_  :				int	   =		GPTaTokenizer.from_pretrained(self.tmpdirname      ,     pad_token='''<pad>'''       )

     # Simple input
     A_  :				List[Any]	   =		'''This is a simple input'''
     A_  :				Union[str, Any]	   =		['''This is a simple input looooooooong''', '''This is a simple input''']
     A_  :				Optional[int]	   =		('''This is a simple input''', '''This is a pair''')
     A_  :				List[str]	   =		[
         ('''This is a simple input loooooong''', '''This is a simple input'''),
         ('''This is a simple pair loooooong''', '''This is a simple pair'''),
     ]

     A_  :				List[str]	   =		tokenizer.pad_token_id

     A_  :				Dict	   =		tokenizer(UpperCamelCase__      ,     padding='''max_length'''      ,     max_length=30      ,     return_tensors='''np'''       )
     A_  :				List[Any]	   =		tokenizer(UpperCamelCase__      ,     padding=UpperCamelCase__      ,     truncate=UpperCamelCase__      ,     return_tensors='''np'''       )
     A_  :				Dict	   =		tokenizer(*UpperCamelCase__      ,     padding='''max_length'''      ,     max_length=60      ,     return_tensors='''np'''       )
     A_  :				Union[str, Any]	   =		tokenizer(UpperCamelCase__      ,     padding=UpperCamelCase__      ,     truncate=UpperCamelCase__      ,     return_tensors='''np'''       )

     # s
     # test single string max_length padding
     self.assertEqual(out_s['''input_ids'''].shape[-1]      ,     30       )
     self.assertTrue(pad_token_id in out_s['''input_ids''']       )
     self.assertTrue(0 in out_s['''attention_mask''']       )

     # s2
     # test automatic padding
     self.assertEqual(out_sa['''input_ids'''].shape[-1]      ,     33       )
     # long slice doesn't have padding
     self.assertFalse(pad_token_id in out_sa['''input_ids'''][0]       )
     self.assertFalse(0 in out_sa['''attention_mask'''][0]       )
     # short slice does have padding
     self.assertTrue(pad_token_id in out_sa['''input_ids'''][1]       )
     self.assertTrue(0 in out_sa['''attention_mask'''][1]       )

     # p
     # test single pair max_length padding
     self.assertEqual(out_p['''input_ids'''].shape[-1]      ,     60       )
     self.assertTrue(pad_token_id in out_p['''input_ids''']       )
     self.assertTrue(0 in out_p['''attention_mask''']       )

     # p2
     # test automatic padding pair
     self.assertEqual(out_pa['''input_ids'''].shape[-1]      ,     52       )
     # long slice pair doesn't have padding
     self.assertFalse(pad_token_id in out_pa['''input_ids'''][0]       )
     self.assertFalse(0 in out_pa['''attention_mask'''][0]       )
     # short slice pair does have padding
     self.assertTrue(pad_token_id in out_pa['''input_ids'''][1]       )
     self.assertTrue(0 in out_pa['''attention_mask'''][1]       )







    def 					a_  (							self   :					Optional[int]       ):



     """simple docstring"""

     A_  :				Tuple	   =		'''$$$'''
     A_  :				Dict	   =		GPTaTokenizer.from_pretrained(self.tmpdirname      ,     bos_token=UpperCamelCase__      ,     add_bos_token=UpperCamelCase__       )

     A_  :				List[Any]	   =		'''This is a simple input'''
     A_  :				Dict	   =		['''This is a simple input 1''', '''This is a simple input 2''']

     A_  :				Union[str, Any]	   =		tokenizer.bos_token_id

     A_  :				Dict	   =		tokenizer(UpperCamelCase__       )
     A_  :				str	   =		tokenizer(UpperCamelCase__       )

     self.assertEqual(out_s.input_ids[0]      ,     UpperCamelCase__       )
     self.assertTrue(all(o[0] == bos_token_id for o in out_sa.input_ids       )       )

     A_  :				Any	   =		tokenizer.decode(out_s.input_ids       )
     A_  :				Optional[Any]	   =		tokenizer.batch_decode(out_sa.input_ids       )

     self.assertEqual(decode_s.split()[0]      ,     UpperCamelCase__       )
     self.assertTrue(all(d.split()[0] == bos_token for d in decode_sa       )       )







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



     """simple docstring"""

     pass







    def 					a_  (							self   :					Dict       ):



     """simple docstring"""

     A_  :				Optional[Any]	   =		[self.get_tokenizer(do_lower_case=UpperCamelCase__      ,     add_bos_token=UpperCamelCase__       )]
     for tokenizer in tokenizers:
      with self.subTest(F"""{tokenizer.__class__.__name__}"""       ):
       A_  :				List[Any]	   =		'''Encode this.'''
       A_  :				Dict	   =		'''This one too please.'''
       A_  :				Any	   =		tokenizer.encode(UpperCamelCase__      ,     add_special_tokens=UpperCamelCase__       )
       encoded_sequence += tokenizer.encode(UpperCamelCase__      ,     add_special_tokens=UpperCamelCase__       )
       A_  :				str	   =		tokenizer.encode_plus(
           UpperCamelCase__      ,     UpperCamelCase__      ,     add_special_tokens=UpperCamelCase__      ,     return_special_tokens_mask=UpperCamelCase__      ,     )
       A_  :				str	   =		encoded_sequence_dict['''input_ids''']
       A_  :				Dict	   =		encoded_sequence_dict['''special_tokens_mask''']
       self.assertEqual(len(UpperCamelCase__       )      ,     len(UpperCamelCase__       )       )

       A_  :				int	   =		[
           (x if not special_tokens_mask[i] else None) for i, x in enumerate(UpperCamelCase__       )
       ]
       A_  :				str	   =		[x for x in filtered_sequence if x is not None]
       self.assertEqual(UpperCamelCase__      ,     UpperCamelCase__       )

@require_tokenizers
class        lowercase      (    unittest.TestCase):







    def 					a_  (							self   :					Dict       ):



     """simple docstring"""

     A_  :				Tuple	   =		AutoTokenizer.from_pretrained('''facebook/opt-350m'''      ,     from_slow=UpperCamelCase__       )
     A_  :				Any	   =		'''A photo of a cat'''

     A_  :				Any	   =		tokenizer.encode(
         UpperCamelCase__      ,     )
     self.assertEqual(UpperCamelCase__      ,     [2, 2_50, 13_45, 9, 10, 47_58]       )
     tokenizer.save_pretrained('''test_opt'''       )

     A_  :				Dict	   =		AutoTokenizer.from_pretrained('''./test_opt'''       )
     A_  :				Optional[int]	   =		tokenizer.encode(
         UpperCamelCase__      ,     )
     self.assertEqual(UpperCamelCase__      ,     [2, 2_50, 13_45, 9, 10, 47_58]       )







    def 					a_  (							self   :					Any       ):



     """simple docstring"""

     A_  :				Dict	   =		AutoTokenizer.from_pretrained('''facebook/opt-350m'''      ,     use_slow=UpperCamelCase__       )
     A_  :				Union[str, Any]	   =		'''A photo of a cat'''

     A_  :				Tuple	   =		tokenizer.encode(
         UpperCamelCase__      ,     )
     # Same as above
     self.assertEqual(UpperCamelCase__      ,     [2, 2_50, 13_45, 9, 10, 47_58]       )







    @unittest.skip('''This test is failing because of a bug in the fast tokenizer'''       )
    def 					a_  (							self   :					int       ):



     """simple docstring"""

     A_  :				Tuple	   =		AutoTokenizer.from_pretrained('''facebook/opt-350m'''      ,     from_slow=UpperCamelCase__       )

     A_  :				Any	   =		'''bos'''
     A_  :				int	   =		tokenizer.get_vocab()['''bos''']

     A_  :				Any	   =		'''A photo of a cat'''
     A_  :				Optional[Any]	   =		tokenizer.encode(
         UpperCamelCase__      ,     )
     # We changed the bos token
     self.assertEqual(UpperCamelCase__      ,     [3_19_57, 2_50, 13_45, 9, 10, 47_58]       )
     tokenizer.save_pretrained('''./tok'''       )
     A_  :				Optional[Any]	   =		AutoTokenizer.from_pretrained('''./tok'''       )
     self.assertTrue(tokenizer.is_fast       )
     A_  :				List[Any]	   =		tokenizer.encode(
         UpperCamelCase__      ,     )
     self.assertEqual(UpperCamelCase__      ,     [3_19_57, 2_50, 13_45, 9, 10, 47_58]       )











"""simple docstring"""

from collections import deque
from math import floor
from random import random
from time import time

class        lowercase      :







				def __init__(							self   :					Dict       ):



					"""simple docstring"""

					A_  :				Tuple	   =		{}







				def 					a_  (							self   :					Union[str, Any]      ,     _lowerCamelCase   :					List[Any]      ,     _lowerCamelCase   :					Dict      ,     _lowerCamelCase   :					List[Any]=1       ):



					"""simple docstring"""

					if self.graph.get(_lowerCamelCase       ):
						if self.graph[u].count([w, v]       ) == 0:
							self.graph[u].append([w, v]       )
					else:
						A_  :				int	   =		[[w, v]]
					if not self.graph.get(_lowerCamelCase       ):
						A_  :				List[Any]	   =		[]







				def 					a_  (							self   :					Optional[int]       ):



					"""simple docstring"""

					return list(self.graph       )







				def 					a_  (							self   :					Dict      ,     _lowerCamelCase   :					str      ,     _lowerCamelCase   :					Tuple       ):



					"""simple docstring"""

					if self.graph.get(_lowerCamelCase       ):
						for _ in self.graph[u]:
							if _[1] == v:
								self.graph[u].remove(_lowerCamelCase       )







				def 					a_  (							self   :					Union[str, Any]      ,     _lowerCamelCase   :					Optional[int]=-2      ,     _lowerCamelCase   :					Tuple=-1       ):



					"""simple docstring"""

					if s == d:
						return []
					A_  :				Union[str, Any]	   =		[]
					A_  :				Optional[int]	   =		[]
					if s == -2:
						A_  :				int	   =		list(self.graph       )[0]
					stack.append(_lowerCamelCase       )
					visited.append(_lowerCamelCase       )
					A_  :				Tuple	   =		s

					while True:
						# check if there is any non isolated nodes
						if len(self.graph[s]       ) != 0:
							A_  :				Optional[Any]	   =		s
							for node in self.graph[s]:
								if visited.count(node[1]       ) < 1:
									if node[1] == d:
										visited.append(_lowerCamelCase       )
										return visited
									else:
										stack.append(node[1]       )
										visited.append(node[1]       )
										A_  :				Union[str, Any]	   =		node[1]
										break

            # check if all the children are visited
						if s == ss:
							stack.pop()
							if len(_lowerCamelCase       ) != 0:
								A_  :				Optional[int]	   =		stack[len(_lowerCamelCase       ) - 1]
						else:
							A_  :				List[Any]	   =		ss

						# check if se have reached the starting point
						if len(_lowerCamelCase       ) == 0:
							return visited







				def 					a_  (							self   :					Dict      ,     _lowerCamelCase   :					List[Any]=-1       ):



					"""simple docstring"""

					if c == -1:
						A_  :				List[Any]	   =		floor(random() * 1_00_00       ) + 10
					for i in range(_lowerCamelCase       ):
						# every vertex has max 100 edges
						for _ in range(floor(random() * 1_02       ) + 1       ):
							A_  :				Tuple	   =		floor(random() * c       ) + 1
							if n != i:
								self.add_pair(_lowerCamelCase      ,     _lowerCamelCase      ,     1       )







				def 					a_  (							self   :					Optional[int]      ,     _lowerCamelCase   :					Union[str, Any]=-2       ):



					"""simple docstring"""

					A_  :				List[str]	   =		deque()
					A_  :				int	   =		[]
					if s == -2:
						A_  :				Any	   =		list(self.graph       )[0]
					d.append(_lowerCamelCase       )
					visited.append(_lowerCamelCase       )
					while d:
						A_  :				List[Any]	   =		d.popleft()
						if len(self.graph[s]       ) != 0:
							for node in self.graph[s]:
								if visited.count(node[1]       ) < 1:
									d.append(node[1]       )
									visited.append(node[1]       )
					return visited







				def 					a_  (							self   :					Union[str, Any]      ,     _lowerCamelCase   :					Tuple       ):



					"""simple docstring"""

					A_  :				List[Any]	   =		0
					for x in self.graph:
						for y in self.graph[x]:
							if y[1] == u:
								count += 1
					return count







				def 					a_  (							self   :					Any      ,     _lowerCamelCase   :					Optional[Any]       ):



					"""simple docstring"""

					return len(self.graph[u]       )







				def 					a_  (							self   :					Union[str, Any]      ,     _lowerCamelCase   :					Tuple=-2       ):



					"""simple docstring"""

					A_  :				int	   =		[]
					A_  :				Optional[Any]	   =		[]
					if s == -2:
						A_  :				List[str]	   =		list(self.graph       )[0]
					stack.append(_lowerCamelCase       )
					visited.append(_lowerCamelCase       )
					A_  :				str	   =		s
					A_  :				List[Any]	   =		[]

					while True:
						# check if there is any non isolated nodes
						if len(self.graph[s]       ) != 0:
							A_  :				str	   =		s
							for node in self.graph[s]:
								if visited.count(node[1]       ) < 1:
									stack.append(node[1]       )
									visited.append(node[1]       )
									A_  :				List[Any]	   =		node[1]
									break

            # check if all the children are visited
						if s == ss:
							sorted_nodes.append(stack.pop()       )
							if len(_lowerCamelCase       ) != 0:
								A_  :				List[str]	   =		stack[len(_lowerCamelCase       ) - 1]
						else:
							A_  :				int	   =		ss

						# check if se have reached the starting point
						if len(_lowerCamelCase       ) == 0:
							return sorted_nodes







				def 					a_  (							self   :					Dict       ):



					"""simple docstring"""

					A_  :				str	   =		[]
					A_  :				Dict	   =		[]
					A_  :				Dict	   =		list(self.graph       )[0]
					stack.append(_lowerCamelCase       )
					visited.append(_lowerCamelCase       )
					A_  :				Any	   =		-2
					A_  :				List[str]	   =		[]
					A_  :				Dict	   =		s
					A_  :				Tuple	   =		False
					A_  :				List[str]	   =		set()

					while True:
						# check if there is any non isolated nodes
						if len(self.graph[s]       ) != 0:
							A_  :				Dict	   =		s
							for node in self.graph[s]:
								if (
								    visited.count(node[1]       ) > 0
								    and node[1] != parent
								    and indirect_parents.count(node[1]       ) > 0
								    and not on_the_way_back
								):
									A_  :				Tuple	   =		len(_lowerCamelCase       ) - 1
									while len_stack >= 0:
										if stack[len_stack] == node[1]:
											anticipating_nodes.add(node[1]       )
											break
										else:
											anticipating_nodes.add(stack[len_stack]       )
											len_stack -= 1
								if visited.count(node[1]       ) < 1:
									stack.append(node[1]       )
									visited.append(node[1]       )
									A_  :				int	   =		node[1]
									break

            # check if all the children are visited
						if s == ss:
							stack.pop()
							A_  :				Optional[int]	   =		True
							if len(_lowerCamelCase       ) != 0:
								A_  :				Union[str, Any]	   =		stack[len(_lowerCamelCase       ) - 1]
						else:
							A_  :				int	   =		False
							indirect_parents.append(_lowerCamelCase       )
							A_  :				Dict	   =		s
							A_  :				Optional[int]	   =		ss

						# check if se have reached the starting point
						if len(_lowerCamelCase       ) == 0:
							return list(_lowerCamelCase       )







				def 					a_  (							self   :					List[str]       ):



					"""simple docstring"""

					A_  :				Dict	   =		[]
					A_  :				Dict	   =		[]
					A_  :				Optional[Any]	   =		list(self.graph       )[0]
					stack.append(_lowerCamelCase       )
					visited.append(_lowerCamelCase       )
					A_  :				Optional[Any]	   =		-2
					A_  :				List[str]	   =		[]
					A_  :				List[Any]	   =		s
					A_  :				int	   =		False
					A_  :				Any	   =		set()

					while True:
						# check if there is any non isolated nodes
						if len(self.graph[s]       ) != 0:
							A_  :				Union[str, Any]	   =		s
							for node in self.graph[s]:
								if (
								    visited.count(node[1]       ) > 0
								    and node[1] != parent
								    and indirect_parents.count(node[1]       ) > 0
								    and not on_the_way_back
								):
									A_  :				Dict	   =		len(_lowerCamelCase       ) - 1
									while len_stack_minus_one >= 0:
										if stack[len_stack_minus_one] == node[1]:
											anticipating_nodes.add(node[1]       )
											break
										else:
											return True
								if visited.count(node[1]       ) < 1:
									stack.append(node[1]       )
									visited.append(node[1]       )
									A_  :				Any	   =		node[1]
									break

            # check if all the children are visited
						if s == ss:
							stack.pop()
							A_  :				str	   =		True
							if len(_lowerCamelCase       ) != 0:
								A_  :				Optional[int]	   =		stack[len(_lowerCamelCase       ) - 1]
						else:
							A_  :				Tuple	   =		False
							indirect_parents.append(_lowerCamelCase       )
							A_  :				int	   =		s
							A_  :				List[Any]	   =		ss

						# check if se have reached the starting point
						if len(_lowerCamelCase       ) == 0:
							return False







				def 					a_  (							self   :					Tuple      ,     _lowerCamelCase   :					Union[str, Any]=-2      ,     _lowerCamelCase   :					int=-1       ):



					"""simple docstring"""

					A_  :				int	   =		time()
					self.dfs(_lowerCamelCase      ,     _lowerCamelCase       )
					A_  :				int	   =		time()
					return end - begin







				def 					a_  (							self   :					Optional[Any]      ,     _lowerCamelCase   :					str=-2       ):



					"""simple docstring"""

					A_  :				int	   =		time()
					self.bfs(_lowerCamelCase       )
					A_  :				Union[str, Any]	   =		time()
					return end - begin

class        lowercase      :







				def __init__(							self   :					Any       ):



					"""simple docstring"""

					A_  :				Tuple	   =		{}







				def 					a_  (							self   :					List[Any]      ,     _lowerCamelCase   :					Optional[Any]      ,     _lowerCamelCase   :					Optional[Any]      ,     _lowerCamelCase   :					Optional[int]=1       ):



					"""simple docstring"""

					if self.graph.get(_lowerCamelCase       ):
						# if there already is a edge
						if self.graph[u].count([w, v]       ) == 0:
							self.graph[u].append([w, v]       )
					else:
						# if u does not exist
						A_  :				Union[str, Any]	   =		[[w, v]]
					# add the other way
					if self.graph.get(_lowerCamelCase       ):
						# if there already is a edge
						if self.graph[v].count([w, u]       ) == 0:
							self.graph[v].append([w, u]       )
					else:
						# if u does not exist
						A_  :				Tuple	   =		[[w, u]]







				def 					a_  (							self   :					Dict      ,     _lowerCamelCase   :					Optional[Any]      ,     _lowerCamelCase   :					Dict       ):



					"""simple docstring"""

					if self.graph.get(_lowerCamelCase       ):
						for _ in self.graph[u]:
							if _[1] == v:
								self.graph[u].remove(_lowerCamelCase       )
        # the other way round
					if self.graph.get(_lowerCamelCase       ):
						for _ in self.graph[v]:
							if _[1] == u:
								self.graph[v].remove(_lowerCamelCase       )







				def 					a_  (							self   :					Any      ,     _lowerCamelCase   :					str=-2      ,     _lowerCamelCase   :					int=-1       ):



					"""simple docstring"""

					if s == d:
						return []
					A_  :				Optional[Any]	   =		[]
					A_  :				List[Any]	   =		[]
					if s == -2:
						A_  :				Optional[int]	   =		list(self.graph       )[0]
					stack.append(_lowerCamelCase       )
					visited.append(_lowerCamelCase       )
					A_  :				Union[str, Any]	   =		s

					while True:
						# check if there is any non isolated nodes
						if len(self.graph[s]       ) != 0:
							A_  :				Any	   =		s
							for node in self.graph[s]:
								if visited.count(node[1]       ) < 1:
									if node[1] == d:
										visited.append(_lowerCamelCase       )
										return visited
									else:
										stack.append(node[1]       )
										visited.append(node[1]       )
										A_  :				int	   =		node[1]
										break

            # check if all the children are visited
						if s == ss:
							stack.pop()
							if len(_lowerCamelCase       ) != 0:
								A_  :				List[Any]	   =		stack[len(_lowerCamelCase       ) - 1]
						else:
							A_  :				str	   =		ss

						# check if se have reached the starting point
						if len(_lowerCamelCase       ) == 0:
							return visited







				def 					a_  (							self   :					Optional[Any]      ,     _lowerCamelCase   :					Union[str, Any]=-1       ):



					"""simple docstring"""

					if c == -1:
						A_  :				List[Any]	   =		floor(random() * 1_00_00       ) + 10
					for i in range(_lowerCamelCase       ):
						# every vertex has max 100 edges
						for _ in range(floor(random() * 1_02       ) + 1       ):
							A_  :				List[str]	   =		floor(random() * c       ) + 1
							if n != i:
								self.add_pair(_lowerCamelCase      ,     _lowerCamelCase      ,     1       )







				def 					a_  (							self   :					Dict      ,     _lowerCamelCase   :					List[Any]=-2       ):



					"""simple docstring"""

					A_  :				Dict	   =		deque()
					A_  :				Tuple	   =		[]
					if s == -2:
						A_  :				List[str]	   =		list(self.graph       )[0]
					d.append(_lowerCamelCase       )
					visited.append(_lowerCamelCase       )
					while d:
						A_  :				str	   =		d.popleft()
						if len(self.graph[s]       ) != 0:
							for node in self.graph[s]:
								if visited.count(node[1]       ) < 1:
									d.append(node[1]       )
									visited.append(node[1]       )
					return visited







				def 					a_  (							self   :					Any      ,     _lowerCamelCase   :					int       ):



					"""simple docstring"""

					return len(self.graph[u]       )







				def 					a_  (							self   :					Any       ):



					"""simple docstring"""

					A_  :				Dict	   =		[]
					A_  :				Optional[int]	   =		[]
					A_  :				Union[str, Any]	   =		list(self.graph       )[0]
					stack.append(_lowerCamelCase       )
					visited.append(_lowerCamelCase       )
					A_  :				str	   =		-2
					A_  :				int	   =		[]
					A_  :				Optional[Any]	   =		s
					A_  :				str	   =		False
					A_  :				int	   =		set()

					while True:
						# check if there is any non isolated nodes
						if len(self.graph[s]       ) != 0:
							A_  :				Tuple	   =		s
							for node in self.graph[s]:
								if (
								    visited.count(node[1]       ) > 0
								    and node[1] != parent
								    and indirect_parents.count(node[1]       ) > 0
								    and not on_the_way_back
								):
									A_  :				Tuple	   =		len(_lowerCamelCase       ) - 1
									while len_stack >= 0:
										if stack[len_stack] == node[1]:
											anticipating_nodes.add(node[1]       )
											break
										else:
											anticipating_nodes.add(stack[len_stack]       )
											len_stack -= 1
								if visited.count(node[1]       ) < 1:
									stack.append(node[1]       )
									visited.append(node[1]       )
									A_  :				str	   =		node[1]
									break

            # check if all the children are visited
						if s == ss:
							stack.pop()
							A_  :				Union[str, Any]	   =		True
							if len(_lowerCamelCase       ) != 0:
								A_  :				Tuple	   =		stack[len(_lowerCamelCase       ) - 1]
						else:
							A_  :				str	   =		False
							indirect_parents.append(_lowerCamelCase       )
							A_  :				Union[str, Any]	   =		s
							A_  :				List[str]	   =		ss

						# check if se have reached the starting point
						if len(_lowerCamelCase       ) == 0:
							return list(_lowerCamelCase       )







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



					"""simple docstring"""

					A_  :				List[str]	   =		[]
					A_  :				int	   =		[]
					A_  :				List[Any]	   =		list(self.graph       )[0]
					stack.append(_lowerCamelCase       )
					visited.append(_lowerCamelCase       )
					A_  :				int	   =		-2
					A_  :				Tuple	   =		[]
					A_  :				Any	   =		s
					A_  :				Tuple	   =		False
					A_  :				Union[str, Any]	   =		set()

					while True:
						# check if there is any non isolated nodes
						if len(self.graph[s]       ) != 0:
							A_  :				Any	   =		s
							for node in self.graph[s]:
								if (
								    visited.count(node[1]       ) > 0
								    and node[1] != parent
								    and indirect_parents.count(node[1]       ) > 0
								    and not on_the_way_back
								):
									A_  :				Optional[int]	   =		len(_lowerCamelCase       ) - 1
									while len_stack_minus_one >= 0:
										if stack[len_stack_minus_one] == node[1]:
											anticipating_nodes.add(node[1]       )
											break
										else:
											return True
								if visited.count(node[1]       ) < 1:
									stack.append(node[1]       )
									visited.append(node[1]       )
									A_  :				Optional[Any]	   =		node[1]
									break

            # check if all the children are visited
						if s == ss:
							stack.pop()
							A_  :				Optional[int]	   =		True
							if len(_lowerCamelCase       ) != 0:
								A_  :				str	   =		stack[len(_lowerCamelCase       ) - 1]
						else:
							A_  :				List[Any]	   =		False
							indirect_parents.append(_lowerCamelCase       )
							A_  :				List[Any]	   =		s
							A_  :				List[Any]	   =		ss

						# check if se have reached the starting point
						if len(_lowerCamelCase       ) == 0:
							return False







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



					"""simple docstring"""

					return list(self.graph       )







				def 					a_  (							self   :					Tuple      ,     _lowerCamelCase   :					Union[str, Any]=-2      ,     _lowerCamelCase   :					str=-1       ):



					"""simple docstring"""

					A_  :				Optional[int]	   =		time()
					self.dfs(_lowerCamelCase      ,     _lowerCamelCase       )
					A_  :				Union[str, Any]	   =		time()
					return end - begin







				def 					a_  (							self   :					Tuple      ,     _lowerCamelCase   :					str=-2       ):



					"""simple docstring"""

					A_  :				Optional[int]	   =		time()
					self.bfs(_lowerCamelCase       )
					A_  :				List[str]	   =		time()
					return end - begin





