



'''simple docstring'''






import os
import unicodedata
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import SPIECE_UNDERLINE, logging


lowerCAmelCase: List[Any]							=						logging.get_logger(__name__)

lowerCAmelCase: Union[str, Any]							=						{'vocab_file': 'spiece.model'}

lowerCAmelCase: Any							=						{
    'vocab_file': {
        'TsinghuaAI/CPM-Generate': 'https://huggingface.co/TsinghuaAI/CPM-Generate/resolve/main/spiece.model',
    }
}

class 							a__( lowerCamelCase__     ):







    def __init__(				self			:  List[Any]						,      __snake_case			:  int						,      __snake_case			:  int=False						,      __snake_case			:  Optional[Any]=True						,      __snake_case			:  List[Any]=False						,      __snake_case			:  Optional[int]="<s>"						,      __snake_case			:  int="</s>"						,      __snake_case			:  List[str]="<unk>"						,      __snake_case			:  List[Any]="<sep>"						,      __snake_case			:  List[str]="<pad>"						,      __snake_case			:  Tuple="<cls>"						,      __snake_case			:  int="<mask>"						,      __snake_case			:  List[Any]=["<eop>", "<eod>"]						,      __snake_case			:  Optional[Dict[str, Any]] = None						,      **__snake_case			:  List[str]						,      ):
      a						: int					       =					AddedToken(__snake_case						,      lstrip=__snake_case						,      rstrip=__snake_case     ) if isinstance(__snake_case						,      __snake_case     ) else mask_token

      a						: Tuple					       =					{} if sp_model_kwargs is None else sp_model_kwargs

      super().__init__(
          do_lower_case=__snake_case						,      remove_space=__snake_case						,      keep_accents=__snake_case						,      bos_token=__snake_case						,      eos_token=__snake_case						,      unk_token=__snake_case						,      sep_token=__snake_case						,      pad_token=__snake_case						,      cls_token=__snake_case						,      mask_token=__snake_case						,      additional_special_tokens=__snake_case						,      sp_model_kwargs=self.sp_model_kwargs						,      **__snake_case						,      )

      a						: List[Any]					       =					3

      a						: List[Any]					       =					do_lower_case
      a						: List[Any]					       =					remove_space
      a						: List[Any]					       =					keep_accents
      a						: List[Any]					       =					vocab_file

      a						: Any					       =					spm.SentencePieceProcessor(**self.sp_model_kwargs     )
      self.sp_model.Load(__snake_case     )

      try:
        import jieba
      except ModuleNotFoundError as error:
        raise error.__class__(
            'You need to install jieba to use CpmTokenizer or CpmTokenizerFast. '
            'See https://pypi.org/project/jieba/ for installation.'     )
      a						: Optional[Any]					       =					jieba
      a						: List[str]					       =					str.maketrans(' \n'						,      '\u2582\u2583'     )







    @property
    # Copied from transformers.models.xlnet.tokenization_xlnet.XLNetTokenizer.vocab_size
    def       lowercase_	(				self			:  Union[str, Any]     ):
      return len(self.sp_model     )







    def       lowercase_	(				self			:  List[Any]     ):
      a						: List[str]					       =					{self.convert_ids_to_tokens(__snake_case     ): i for i in range(self.vocab_size     )}
      vocab.update(self.added_tokens_encoder     )
      return vocab







    def __getstate__(				self			:  Optional[int]     ):
      a						: Dict					       =					self.__dict__.copy()
      a						: int					       =					None
      return state







    def __setstate__(				self			:  int						,      __snake_case			:  Tuple     ):
      a						: Optional[Any]					       =					d

      # for backward compatibility
      if not hasattr(self						,      'sp_model_kwargs'     ):
        a						: int					       =					{}

      a						: Tuple					       =					spm.SentencePieceProcessor(**self.sp_model_kwargs     )
      self.sp_model.Load(self.vocab_file     )







    def       lowercase_	(				self			:  List[str]						,      __snake_case			:  Tuple     ):
      if self.remove_space:
        a						: Optional[Any]					       =					' '.join(inputs.strip().split()     )
      else:
        a						: str					       =					inputs
      a						: List[Any]					       =					outputs.replace('``'						,      '"'     ).replace('\'\''						,      '"'     )

      if not self.keep_accents:
        a						: List[Any]					       =					unicodedata.normalize('NFKD'						,      __snake_case     )
        a						: str					       =					''.join([c for c in outputs if not unicodedata.combining(__snake_case     )]     )
      if self.do_lower_case:
        a						: Dict					       =					outputs.lower()

      return outputs







    def       lowercase_	(				self			:  Dict						,      __snake_case			:  str     ):
      a						: Dict					       =					self.preprocess_text(__snake_case     )
      a						: Union[str, Any]					       =					self.sp_model.encode(__snake_case						,      out_type=__snake_case     )
      a						: Tuple					       =					[]
      for piece in pieces:
        if len(__snake_case     ) > 1 and piece[-1] == str(','     ) and piece[-2].isdigit():
          a						: int					       =					self.sp_model.EncodeAsPieces(piece[:-1].replace(__snake_case						,      ''     )     )
          if piece[0] != SPIECE_UNDERLINE and cur_pieces[0][0] == SPIECE_UNDERLINE:
            if len(cur_pieces[0]     ) == 1:
              a						: List[str]					       =					cur_pieces[1:]
            else:
              a						: Union[str, Any]					       =					cur_pieces[0][1:]
          cur_pieces.append(piece[-1]     )
          new_pieces.extend(__snake_case     )
        else:
          new_pieces.append(__snake_case     )

      return new_pieces







    def       lowercase_	(				self			:  Dict						,      __snake_case			:  List[Any]     ):
      return self.sp_model.PieceToId(__snake_case     )







    def       lowercase_	(				self			:  List[str]						,      __snake_case			:  Tuple     ):
      return self.sp_model.IdToPiece(__snake_case     )







    def       lowercase_	(				self			:  Union[str, Any]						,      __snake_case			:  Dict     ):
      a						: Union[str, Any]					       =					''.join(__snake_case     ).replace(__snake_case						,      ' '     ).strip()
      return out_string







    def       lowercase_	(				self			:  Optional[Any]						,      __snake_case			:  List[int]						,      __snake_case			:  Optional[List[int]] = None     ):
      a						: List[Any]					       =					[self.sep_token_id]
      a						: Dict					       =					[self.cls_token_id]
      if token_ids_a is None:
        return token_ids_a + sep + cls
      return token_ids_a + sep + token_ids_a + sep + cls







    def       lowercase_	(				self			:  List[Any]						,      __snake_case			:  List[int]						,      __snake_case			:  Optional[List[int]] = None						,      __snake_case			:  bool = False     ):

      if already_has_special_tokens:
        return super().get_special_tokens_mask(
            token_ids_a=__snake_case						,      token_ids_a=__snake_case						,      already_has_special_tokens=__snake_case     )

      if token_ids_a is not None:
        return ([0] * len(__snake_case     )) + [1] + ([0] * len(__snake_case     )) + [1, 1]
      return ([0] * len(__snake_case     )) + [1, 1]







    def       lowercase_	(				self			:  Union[str, Any]						,      __snake_case			:  List[int]						,      __snake_case			:  Optional[List[int]] = None     ):
      a						: List[str]					       =					[self.sep_token_id]
      a						: Optional[Any]					       =					[2]

      if token_ids_a is None:
        return len(token_ids_a + sep     ) * [0] + cls_segment_id
      return len(token_ids_a + sep     ) * [0] + len(token_ids_a + sep     ) * [1] + cls_segment_id







    def       lowercase_	(				self			:  Any						,      __snake_case			:  str						,      __snake_case			:  Optional[str] = None     ):
      if not os.path.isdir(__snake_case     ):
        logger.error(F"""Vocabulary path ({save_directory}) should be a directory"""     )
        return
      a						: Any					       =					os.path.join(
          __snake_case						,      (filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['vocab_file']     )

      if os.path.abspath(self.vocab_file     ) != os.path.abspath(__snake_case     ) and os.path.isfile(self.vocab_file     ):
        copyfile(self.vocab_file						,      __snake_case     )
      elif not os.path.isfile(self.vocab_file     ):
        with open(__snake_case						,      'wb'     ) as fi:
          a						: Any					       =					self.sp_model.serialized_model_proto()
          fi.write(__snake_case     )

      return (out_vocab_file,)







    def       lowercase_	(				self			:  List[Any]						,      *__snake_case			:  Dict						,      **__snake_case			:  Optional[Any]     ):
      a						: Any					       =					super()._decode(*__snake_case						,      **__snake_case     )
      a						: List[Any]					       =					text.replace(' '						,      ''     ).replace('\u2582'						,      ' '     ).replace('\u2583'						,      '\n'     )
      return text




'''simple docstring'''






import math

class 							a__:







    def __init__(				self			:  int						,      __snake_case			:  Any=0     ):  # a graph with Node 0,1,...,N-1
      a						: List[Any]					       =					n
      a						: Optional[Any]					       =					[
          [math.inf for j in range(0						,      __snake_case     )] for i in range(0						,      __snake_case     )
      ]  # adjacency matrix for weight
      a						: Dict					       =					[
          [math.inf for j in range(0						,      __snake_case     )] for i in range(0						,      __snake_case     )
      ]  # dp[i][j] stores minimum distance from i to j







    def       lowercase_	(				self			:  int						,      __snake_case			:  str						,      __snake_case			:  Tuple						,      __snake_case			:  int     ):
      a						: str					       =					w







    def       lowercase_	(				self			:  int     ):
      for k in range(0						,      self.n     ):
        for i in range(0						,      self.n     ):
          for j in range(0						,      self.n     ):
            a						: str					       =					min(self.dp[i][j]						,      self.dp[i][k] + self.dp[k][j]     )







    def       lowercase_	(				self			:  List[str]						,      __snake_case			:  Any						,      __snake_case			:  List[str]     ):
      return self.dp[u][v]


if __name__ == "__main__":
     lowerCAmelCase: Any							=						Graph(5)
     graph.add_edge(0, 2, 9)
     graph.add_edge(0, 4, 1_0)
     graph.add_edge(1, 3, 5)
     graph.add_edge(2, 3, 7)
     graph.add_edge(3, 0, 1_0)
     graph.add_edge(3, 1, 2)
     graph.add_edge(3, 2, 1)
     graph.add_edge(3, 4, 6)
     graph.add_edge(4, 1, 3)
     graph.add_edge(4, 2, 4)
     graph.add_edge(4, 3, 9)
     graph.floyd_warshall()
     graph.show_min(1, 4)
     graph.show_min(0, 3)