'''simple docstring'''






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





class     A__							:





   """simple docstring"""





   def __init__( self     :		Any			)       ->    Any:







      """simple docstring"""




      _UpperCAmelCase							:	List[Any]							=   {}




   def 			_lowerCAmelCase		( self     :		List[str]						,     lowerCAmelCase__     :		str						,     lowerCAmelCase__     :		Union[str, Any]						,     lowerCAmelCase__     :		Optional[int]=1			)       ->    Optional[int]:







      """simple docstring"""




      if self.graph.get(a__			):
         if self.graph[u].count([w, v]			) == 0:
            self.graph[u].append([w, v]			)
      else:
         _UpperCAmelCase							:	Optional[int]							=   [[w, v]]
      if not self.graph.get(a__			):
         _UpperCAmelCase							:	int							=   []




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







      """simple docstring"""




      return list(self.graph			)




   def 			_lowerCAmelCase		( self     :		Tuple						,     lowerCAmelCase__     :		Any						,     lowerCAmelCase__     :		Any			)       ->    int:







      """simple docstring"""




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




   def 			_lowerCAmelCase		( self     :		Any						,     lowerCAmelCase__     :		List[Any]=-2						,     lowerCAmelCase__     :		Optional[int]=-1			)       ->    int:







      """simple docstring"""




      if s == d:
         return []
      _UpperCAmelCase							:	Any							=   []
      _UpperCAmelCase							:	List[Any]							=   []
      if s == -2:
         _UpperCAmelCase							:	Dict							=   list(self.graph			)[0]
      stack.append(a__			)
      visited.append(a__			)
      _UpperCAmelCase							:	int							=   s

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

            # check if all the children are visited
         if s == ss:
            stack.pop()
            if len(a__			) != 0:
               _UpperCAmelCase							:	Tuple							=   stack[len(a__			) - 1]
         else:
            _UpperCAmelCase							:	Union[str, Any]							=   ss

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




   def 			_lowerCAmelCase		( self     :		List[str]						,     lowerCAmelCase__     :		Dict=-1			)       ->    Dict:







      """simple docstring"""




      if c == -1:
         _UpperCAmelCase							:	Union[str, Any]							=   floor(random() * 1_0_0_0_0			) + 1_0
      for i in range(a__			):
         # every vertex has max 100 edges
         for _ in range(floor(random() * 1_0_2			) + 1			):
            _UpperCAmelCase							:	List[str]							=   floor(random() * c			) + 1
            if n != i:
               self.add_pair(a__						,     a__						,     1			)




   def 			_lowerCAmelCase		( self     :		Dict						,     lowerCAmelCase__     :		List[Any]=-2			)       ->    Optional[Any]:







      """simple docstring"""




      _UpperCAmelCase							:	List[Any]							=   deque()
      _UpperCAmelCase							:	int							=   []
      if s == -2:
         _UpperCAmelCase							:	List[Any]							=   list(self.graph			)[0]
      d.append(a__			)
      visited.append(a__			)
      while d:
         _UpperCAmelCase							:	Optional[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 			_lowerCAmelCase		( self     :		List[Any]						,     lowerCAmelCase__     :		Dict			)       ->    Optional[Any]:







      """simple docstring"""




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




   def 			_lowerCAmelCase		( self     :		Tuple						,     lowerCAmelCase__     :		Tuple			)       ->    int:







      """simple docstring"""




      return len(self.graph[u]			)




   def 			_lowerCAmelCase		( self     :		Optional[int]						,     lowerCAmelCase__     :		Dict=-2			)       ->    Tuple:







      """simple docstring"""




      _UpperCAmelCase							:	Dict							=   []
      _UpperCAmelCase							:	List[Any]							=   []
      if s == -2:
         _UpperCAmelCase							:	Tuple							=   list(self.graph			)[0]
      stack.append(a__			)
      visited.append(a__			)
      _UpperCAmelCase							:	Dict							=   s
      _UpperCAmelCase							:	List[Any]							=   []

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

            # check if all the children are visited
         if s == ss:
            sorted_nodes.append(stack.pop()			)
            if len(a__			) != 0:
               _UpperCAmelCase							:	List[str]							=   stack[len(a__			) - 1]
         else:
            _UpperCAmelCase							:	Union[str, Any]							=   ss

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




   def 			_lowerCAmelCase		( self     :		List[Any]			)       ->    Optional[int]:







      """simple docstring"""




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

      while True:
         # check if there is any non isolated nodes
         if len(self.graph[s]			) != 0:
            _UpperCAmelCase							:	str							=   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
               ):
                  _UpperCAmelCase							:	Any							=   len(a__			) - 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]			)
                  _UpperCAmelCase							:	Dict							=   node[1]
                  break

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

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




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







      """simple docstring"""




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

      while True:
         # check if there is any non isolated nodes
         if len(self.graph[s]			) != 0:
            _UpperCAmelCase							:	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
               ):
                  _UpperCAmelCase							:	int							=   len(a__			) - 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]			)
                  _UpperCAmelCase							:	str							=   node[1]
                  break

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

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




   def 			_lowerCAmelCase		( self     :		Optional[Any]						,     lowerCAmelCase__     :		Tuple=-2						,     lowerCAmelCase__     :		List[Any]=-1			)       ->    int:







      """simple docstring"""




      _UpperCAmelCase							:	Dict							=   time()
      self.dfs(a__						,     a__			)
      _UpperCAmelCase							:	List[str]							=   time()
      return end - begin




   def 			_lowerCAmelCase		( self     :		int						,     lowerCAmelCase__     :		Union[str, Any]=-2			)       ->    List[str]:







      """simple docstring"""




      _UpperCAmelCase							:	Optional[Any]							=   time()
      self.bfs(a__			)
      _UpperCAmelCase							:	int							=   time()
      return end - begin





class     A__							:





   """simple docstring"""





   def __init__( self     :		List[str]			)       ->    Any:







      """simple docstring"""




      _UpperCAmelCase							:	Tuple							=   {}




   def 			_lowerCAmelCase		( self     :		Dict						,     lowerCAmelCase__     :		List[str]						,     lowerCAmelCase__     :		Optional[Any]						,     lowerCAmelCase__     :		Dict=1			)       ->    Optional[Any]:







      """simple docstring"""




      if self.graph.get(a__			):
         # 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
         _UpperCAmelCase							:	Any							=   [[w, v]]
      # add the other way
      if self.graph.get(a__			):
         # 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
         _UpperCAmelCase							:	Union[str, Any]							=   [[w, u]]




   def 			_lowerCAmelCase		( self     :		Dict						,     lowerCAmelCase__     :		Optional[int]						,     lowerCAmelCase__     :		Optional[Any]			)       ->    Optional[int]:







      """simple docstring"""




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




   def 			_lowerCAmelCase		( self     :		Union[str, Any]						,     lowerCAmelCase__     :		int=-2						,     lowerCAmelCase__     :		Union[str, Any]=-1			)       ->    List[Any]:







      """simple docstring"""




      if s == d:
         return []
      _UpperCAmelCase							:	Dict							=   []
      _UpperCAmelCase							:	int							=   []
      if s == -2:
         _UpperCAmelCase							:	List[str]							=   list(self.graph			)[0]
      stack.append(a__			)
      visited.append(a__			)
      _UpperCAmelCase							:	Optional[int]							=   s

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

            # check if all the children are visited
         if s == ss:
            stack.pop()
            if len(a__			) != 0:
               _UpperCAmelCase							:	Optional[Any]							=   stack[len(a__			) - 1]
         else:
            _UpperCAmelCase							:	Tuple							=   ss

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




   def 			_lowerCAmelCase		( self     :		List[Any]						,     lowerCAmelCase__     :		Tuple=-1			)       ->    Dict:







      """simple docstring"""




      if c == -1:
         _UpperCAmelCase							:	int							=   floor(random() * 1_0_0_0_0			) + 1_0
      for i in range(a__			):
         # every vertex has max 100 edges
         for _ in range(floor(random() * 1_0_2			) + 1			):
            _UpperCAmelCase							:	Dict							=   floor(random() * c			) + 1
            if n != i:
               self.add_pair(a__						,     a__						,     1			)




   def 			_lowerCAmelCase		( self     :		int						,     lowerCAmelCase__     :		Union[str, Any]=-2			)       ->    Union[str, Any]:







      """simple docstring"""




      _UpperCAmelCase							:	int							=   deque()
      _UpperCAmelCase							:	List[str]							=   []
      if s == -2:
         _UpperCAmelCase							:	Optional[int]							=   list(self.graph			)[0]
      d.append(a__			)
      visited.append(a__			)
      while d:
         _UpperCAmelCase							:	List[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 			_lowerCAmelCase		( self     :		int						,     lowerCAmelCase__     :		Dict			)       ->    str:







      """simple docstring"""




      return len(self.graph[u]			)




   def 			_lowerCAmelCase		( self     :		List[str]			)       ->    Dict:







      """simple docstring"""




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

      while True:
         # check if there is any non isolated nodes
         if len(self.graph[s]			) != 0:
            _UpperCAmelCase							:	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
               ):
                  _UpperCAmelCase							:	Dict							=   len(a__			) - 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]			)
                  _UpperCAmelCase							:	Any							=   node[1]
                  break

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

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




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







      """simple docstring"""




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

      while True:
         # check if there is any non isolated nodes
         if len(self.graph[s]			) != 0:
            _UpperCAmelCase							:	int							=   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
               ):
                  _UpperCAmelCase							:	Optional[int]							=   len(a__			) - 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]			)
                  _UpperCAmelCase							:	Tuple							=   node[1]
                  break

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

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




   def 			_lowerCAmelCase		( self     :		Optional[int]			)       ->    Any:







      """simple docstring"""




      return list(self.graph			)




   def 			_lowerCAmelCase		( self     :		Any						,     lowerCAmelCase__     :		List[str]=-2						,     lowerCAmelCase__     :		List[str]=-1			)       ->    Dict:







      """simple docstring"""




      _UpperCAmelCase							:	Optional[int]							=   time()
      self.dfs(a__						,     a__			)
      _UpperCAmelCase							:	Dict							=   time()
      return end - begin




   def 			_lowerCAmelCase		( self     :		List[str]						,     lowerCAmelCase__     :		int=-2			)       ->    Optional[Any]:







      """simple docstring"""




      _UpperCAmelCase							:	Union[str, Any]							=   time()
      self.bfs(a__			)
      _UpperCAmelCase							:	Optional[Any]							=   time()
      return end - begin






import os
import unittest

from transformers.models.cpmant.tokenization_cpmant import VOCAB_FILES_NAMES, CpmAntTokenizer
from transformers.testing_utils import require_jieba, tooslow

from ...test_tokenization_common import TokenizerTesterMixin

@require_jieba
class 		SCREAMING_SNAKE_CASE__				(       _UpperCAmelCase						,      unittest.TestCase  ):
      A_						:				List[str]							=    CpmAntTokenizer
      A_						:				Optional[int]							=    False


      def    a (self       :      Optional[int]      ):





         """simple docstring"""



         super().setUp()

         __snake_case							       =   [
             '''<d>''',
             '''</d>''',
             '''<s>''',
             '''</s>''',
             '''</_>''',
             '''<unk>''',
             '''<pad>''',
             '''</n>''',
             '''我''',
             '''是''',
             '''C''',
             '''P''',
             '''M''',
             '''A''',
             '''n''',
             '''t''',
         ]
         __snake_case							       =   os.path.join(self.tmpdirname				,			VOCAB_FILES_NAMES['''vocab_file''']      )
         with open(self.vocab_file				,			'''w'''				,			encoding='''utf-8'''      ) as vocab_writer:
            vocab_writer.write(''''''.join([x + '''\n''' for x in vocab_tokens]      )      )


      @tooslow
      def    a (self       :      Dict      ):





         """simple docstring"""



         __snake_case							       =   CpmAntTokenizer.from_pretrained('''openbmb/cpm-ant-10b'''      )
         __snake_case							       =   '''今天天气真好！'''
         __snake_case							       =   ['''今天''', '''天气''', '''真''', '''好''', '''！''']
         __snake_case							       =   tokenizer.tokenize(a__      )
         self.assertListEqual(a__				,			a__      )
         __snake_case							       =   '''今天天气真好！'''
         __snake_case							       =   [tokenizer.bos_token] + tokens

         __snake_case							       =   [6, 9802, 1_4962, 2082, 831, 244]
         self.assertListEqual(tokenizer.convert_tokens_to_ids(a__      )				,			a__      )

         __snake_case							       =   tokenizer.decode(a__      )
         self.assertEqual(a__				,			a__      )

