
from collections import deque







def 		_snake_case(						SCREAMING_SNAKE_CASE__       )				->					str:
       return input(SCREAMING_SNAKE_CASE__       ).strip().split(""" """       )







def 		_snake_case(						SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__       )				->					dict[int, list[int]]:
       lowercase							:  dict[int, list[int]] 			=   {}
       for i in range(SCREAMING_SNAKE_CASE__       ):
              lowercase							:  List[str] 			=   []

       for e in range(SCREAMING_SNAKE_CASE__       ):
              lowercase			,    lowercase							:  Optional[Any] 			=   (int(SCREAMING_SNAKE_CASE__       ) for i in _input(f"Edge {e + 1}: <node1> <node2> "       ))
              graph[x].append(SCREAMING_SNAKE_CASE__       )
       return graph







def 		_snake_case(						SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__       )				->					dict[int, list[int]]:
       lowercase							:  dict[int, list[int]] 			=   {}
       for i in range(SCREAMING_SNAKE_CASE__       ):
              lowercase							:  Dict 			=   []

       for e in range(SCREAMING_SNAKE_CASE__       ):
              lowercase			,    lowercase							:  List[Any] 			=   (int(SCREAMING_SNAKE_CASE__       ) for i in _input(f"Edge {e + 1}: <node1> <node2> "       ))
              graph[x].append(SCREAMING_SNAKE_CASE__       )
              graph[y].append(SCREAMING_SNAKE_CASE__       )
       return graph







def 		_snake_case(						SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__       )				->					dict[int, list[tuple[int, int]]]:
       lowercase							:  dict[int, list[tuple[int, int]]] 			=   {}
       for i in range(SCREAMING_SNAKE_CASE__       ):
              lowercase							:  List[Any] 			=   []

       for e in range(SCREAMING_SNAKE_CASE__       ):
              lowercase			,    lowercase			,    lowercase							:  Any 			=   (int(SCREAMING_SNAKE_CASE__       ) for i in _input(f"Edge {e + 1}: <node1> <node2> <weight> "       ))
              graph[x].append((y, w)       )
              graph[y].append((x, w)       )
       return graph


if __name__ == "__main__":
  lowercase					,						lowercase						:      List[Any]							=							(int(i) for i in _input("""Number of nodes and edges: """))

  lowercase						:      List[Any]							=							int(
      _input(
          """Press 1 or 2 or 3 \n"""
          """1. Unweighted directed \n"""
          """2. Unweighted undirected \n"""
          """3. Weighted undirected \n"""
      )[0]
  )

  lowercase						:      Any							=							{
      1: initialize_unweighted_directed_graph,
      2: initialize_unweighted_undirected_graph,
      3: initialize_weighted_undirected_graph,
  }[graph_choice](n, m)







def 		_snake_case(						SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__       )				->					Optional[int]:
       lowercase			,    lowercase							:  Union[str, Any] 			=   {s}, [s]
       print(SCREAMING_SNAKE_CASE__       )
       while _s:
              lowercase							:  int 			=   0
              for i in g[_s[-1]]:
                     if i not in vis:
                            _s.append(SCREAMING_SNAKE_CASE__       )
                            vis.add(SCREAMING_SNAKE_CASE__       )
                            lowercase							:  Tuple 			=   1
                            print(SCREAMING_SNAKE_CASE__       )
                            break
              if not flag:
                     _s.pop()







def 		_snake_case(						SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__       )				->					str:
       lowercase			,    lowercase							:  List[str] 			=   {s}, deque([s]       )
       print(SCREAMING_SNAKE_CASE__       )
       while q:
              lowercase							:  Tuple 			=   q.popleft()
              for v in g[u]:
                     if v not in vis:
                            vis.add(SCREAMING_SNAKE_CASE__       )
                            q.append(SCREAMING_SNAKE_CASE__       )
                            print(SCREAMING_SNAKE_CASE__       )







def 		_snake_case(						SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__       )				->					Any:
       lowercase			,    lowercase			,    lowercase							:  Tuple 			=   {s: 0}, set(), {s: 0}
       while True:
              if len(SCREAMING_SNAKE_CASE__       ) == len(SCREAMING_SNAKE_CASE__       ) - 1:
                     break
              lowercase							:  Tuple 			=   100_000
              for i in dist:
                     if i not in known and dist[i] < mini:
                            lowercase							:  Optional[Any] 			=   dist[i]
                            lowercase							:  Tuple 			=   i
              known.add(SCREAMING_SNAKE_CASE__       )
              for v in g[u]:
                     if v[0] not in known and dist[u] + v[1] < dist.get(v[0]      ,			100_000       ):
                            lowercase							:  Tuple 			=   dist[u] + v[1]
                            lowercase							:  Optional[int] 			=   u
       for i in dist:
              if i != s:
                     print(dist[i]       )







def 		_snake_case(						SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__=None      ,			SCREAMING_SNAKE_CASE__=None       )				->					Tuple:
       if q is None:
              lowercase							:  Optional[int] 			=   [1]
       if ind is None:
              lowercase							:  List[str] 			=   [0] * (len(SCREAMING_SNAKE_CASE__       ) + 1)  # SInce oth Index is ignored
              for u in g:
                     for v in g[u]:
                            ind[v] += 1
              lowercase							:  Dict 			=   deque()
              for i in g:
                     if ind[i] == 0:
                            q.append(SCREAMING_SNAKE_CASE__       )
       if len(SCREAMING_SNAKE_CASE__       ) == 0:
              return
       lowercase							:  Optional[int] 			=   q.popleft()
       print(SCREAMING_SNAKE_CASE__       )
       for w in g[v]:
              ind[w] -= 1
              if ind[w] == 0:
                     q.append(SCREAMING_SNAKE_CASE__       )
       topo(SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__       )







def 		_snake_case(						)				->					Optional[int]:
       lowercase							:  Optional[Any] 			=   input().strip()
       lowercase							:  int 			=   []
       for _ in range(SCREAMING_SNAKE_CASE__       ):
              a.append(map(SCREAMING_SNAKE_CASE__      ,			input().strip().split()       )       )
       return a, n







def 		_snake_case(						SCREAMING_SNAKE_CASE__       )				->					Union[str, Any]:
       ((lowercase)			,    (lowercase))							:  int 			=   a_and_n
       lowercase							:  List[Any] 			=   list(SCREAMING_SNAKE_CASE__       )
       lowercase							:  List[str] 			=   [[0] * n for i in range(SCREAMING_SNAKE_CASE__       )]
       for k in range(SCREAMING_SNAKE_CASE__       ):
              for i in range(SCREAMING_SNAKE_CASE__       ):
                     for j in range(SCREAMING_SNAKE_CASE__       ):
                            if dist[i][j] > dist[i][k] + dist[k][j]:
                                   lowercase							:  Union[str, Any] 			=   dist[i][k] + dist[k][j]
                                   lowercase							:  Union[str, Any] 			=   k
       print(SCREAMING_SNAKE_CASE__       )







def 		_snake_case(						SCREAMING_SNAKE_CASE__      ,			SCREAMING_SNAKE_CASE__       )				->					Union[str, Any]:
       lowercase			,    lowercase			,    lowercase							:  Tuple 			=   {s: 0}, set(), {s: 0}
       while True:
              if len(SCREAMING_SNAKE_CASE__       ) == len(SCREAMING_SNAKE_CASE__       ) - 1:
                     break
              lowercase							:  Optional[Any] 			=   100_000
              for i in dist:
                     if i not in known and dist[i] < mini:
                            lowercase							:  Optional[int] 			=   dist[i]
                            lowercase							:  List[Any] 			=   i
              known.add(SCREAMING_SNAKE_CASE__       )
              for v in g[u]:
                     if v[0] not in known and v[1] < dist.get(v[0]      ,			100_000       ):
                            lowercase							:  Optional[Any] 			=   v[1]
                            lowercase							:  List[Any] 			=   u
       return dist







def 		_snake_case(						)				->					Union[str, Any]:
       lowercase			,    lowercase							:  List[Any] 			=   map(SCREAMING_SNAKE_CASE__      ,			input().split(""" """       )       )
       lowercase							:  Optional[int] 			=   []
       for _ in range(SCREAMING_SNAKE_CASE__       ):
              edges.append(map(SCREAMING_SNAKE_CASE__      ,			input().split(""" """       )       )       )
       return edges, n







def 		_snake_case(						SCREAMING_SNAKE_CASE__       )				->					Optional[Any]:
       # Sort edges on the basis of distance
       ((lowercase)			,    (lowercase))							:  Dict 			=   e_and_n
       e.sort(reverse=SCREAMING_SNAKE_CASE__      ,			key=lambda SCREAMING_SNAKE_CASE__       : x[2]       )
       lowercase							:  Tuple 			=   [{i} for i in range(1      ,			n + 1       )]
       while True:
              if len(SCREAMING_SNAKE_CASE__       ) == 1:
                     break
              print(SCREAMING_SNAKE_CASE__       )
              lowercase							:  Tuple 			=   e.pop()
              for i in range(len(SCREAMING_SNAKE_CASE__       )       ):
                     if x[0] in s[i]:
                            break
              for j in range(len(SCREAMING_SNAKE_CASE__       )       ):
                     if x[1] in s[j]:
                            if i == j:
                                   break
                            s[j].update(s[i]       )
                            s.pop(SCREAMING_SNAKE_CASE__       )
                            break







def 		_snake_case(						SCREAMING_SNAKE_CASE__       )				->					Union[str, Any]:
       lowercase							:  Any 			=   []
       for node in graph:
              if not graph[node]:
                     isolated.append(SCREAMING_SNAKE_CASE__       )
       return isolated


from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_keras_nlp_available,
    is_tensorflow_text_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


lowercase						:      Any							=							{
    """configuration_gpt2""": ["""GPT2_PRETRAINED_CONFIG_ARCHIVE_MAP""", """GPT2Config""", """GPT2OnnxConfig"""],
    """tokenization_gpt2""": ["""GPT2Tokenizer"""],
}

try:
  if not is_tokenizers_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  lowercase						:      List[Any]							=							["""GPT2TokenizerFast"""]

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  lowercase						:      str							=							[
      """GPT2_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """GPT2DoubleHeadsModel""",
      """GPT2ForQuestionAnswering""",
      """GPT2ForSequenceClassification""",
      """GPT2ForTokenClassification""",
      """GPT2LMHeadModel""",
      """GPT2Model""",
      """GPT2PreTrainedModel""",
      """load_tf_weights_in_gpt2""",
  ]

try:
  if not is_tf_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  lowercase						:      Tuple							=							[
      """TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """TFGPT2DoubleHeadsModel""",
      """TFGPT2ForSequenceClassification""",
      """TFGPT2LMHeadModel""",
      """TFGPT2MainLayer""",
      """TFGPT2Model""",
      """TFGPT2PreTrainedModel""",
  ]

try:
  if not is_keras_nlp_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  lowercase						:      List[str]							=							["""TFGPT2Tokenizer"""]

try:
  if not is_flax_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  lowercase						:      str							=							["""FlaxGPT2LMHeadModel""", """FlaxGPT2Model""", """FlaxGPT2PreTrainedModel"""]

if TYPE_CHECKING:
  from .configuration_gpta import GPT2_PRETRAINED_CONFIG_ARCHIVE_MAP, GPTaConfig, GPTaOnnxConfig
  from .tokenization_gpta import GPTaTokenizer

  try:
    if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_gpta_fast import GPTaTokenizerFast

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_gpta import (
        GPT2_PRETRAINED_MODEL_ARCHIVE_LIST,
        GPTaDoubleHeadsModel,
        GPTaForQuestionAnswering,
        GPTaForSequenceClassification,
        GPTaForTokenClassification,
        GPTaLMHeadModel,
        GPTaModel,
        GPTaPreTrainedModel,
        load_tf_weights_in_gpta,
    )

  try:
    if not is_tf_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_tf_gpta import (
        TF_GPT2_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFGPTaDoubleHeadsModel,
        TFGPTaForSequenceClassification,
        TFGPTaLMHeadModel,
        TFGPTaMainLayer,
        TFGPTaModel,
        TFGPTaPreTrainedModel,
    )

  try:
    if not is_keras_nlp_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_gpta_tf import TFGPTaTokenizer

  try:
    if not is_flax_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_flax_gpta import FlaxGPTaLMHeadModel, FlaxGPTaModel, FlaxGPTaPreTrainedModel

else:
  import sys

  lowercase						:      Union[str, Any]							=							_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)
