






import posixpath
from pathlib import Path
from unittest.mock import patch

import pytest
from fsspec.implementations.local import AbstractFileSystem, LocalFileSystem, stringify_path
from fsspec.registry import _registry as _fsspec_registry




class        _lowerCAmelCase( __lowerCamelCase      ):





       """simple docstring"""







       a       :	List[str]								='mock'





       def __init__(      self						,    *_lowerCamelCase						,    _lowerCamelCase						,    **_lowerCamelCase							):
         super().__init__()
         UpperCamelCase_:      List[Any]					   =       LocalFileSystem(*_lowerCamelCase						,    **_lowerCamelCase							)
         UpperCamelCase_:      List[str]					   =       Path(_lowerCamelCase							).resolve().as_posix() + '/'





       def     _a					(      self						,    _lowerCamelCase						,    *_lowerCamelCase						,    **_lowerCamelCase							):
         UpperCamelCase_:      int					   =       posixpath.join(self.local_root_dir						,    self._strip_protocol(_lowerCamelCase							)							)
         return self._fs.mkdir(_lowerCamelCase						,    *_lowerCamelCase						,    **_lowerCamelCase							)





       def     _a					(      self						,    _lowerCamelCase						,    *_lowerCamelCase						,    **_lowerCamelCase							):
         UpperCamelCase_:      Dict					   =       posixpath.join(self.local_root_dir						,    self._strip_protocol(_lowerCamelCase							)							)
         return self._fs.makedirs(_lowerCamelCase						,    *_lowerCamelCase						,    **_lowerCamelCase							)





       def     _a					(      self						,    _lowerCamelCase							):
         UpperCamelCase_:      int					   =       posixpath.join(self.local_root_dir						,    self._strip_protocol(_lowerCamelCase							)							)
         return self._fs.rmdir(_lowerCamelCase							)





       def     _a					(      self						,    _lowerCamelCase						,    _lowerCamelCase=True						,    *_lowerCamelCase						,    **_lowerCamelCase							):
         UpperCamelCase_:      Any					   =       posixpath.join(self.local_root_dir						,    self._strip_protocol(_lowerCamelCase							)							)
         UpperCamelCase_:      List[Any]					   =       self._fs.ls(_lowerCamelCase						,    detail=_lowerCamelCase						,    *_lowerCamelCase						,    **_lowerCamelCase							)
         if detail:
           return [{**info, "name": info["name"][len(self.local_root_dir							) :]} for info in out]
         else:
           return [name[len(self.local_root_dir							) :] for name in out]





       def     _a					(      self						,    _lowerCamelCase						,    *_lowerCamelCase						,    **_lowerCamelCase							):
         UpperCamelCase_:      List[Any]					   =       posixpath.join(self.local_root_dir						,    self._strip_protocol(_lowerCamelCase							)							)
         UpperCamelCase_:      Tuple					   =       dict(self._fs.info(_lowerCamelCase						,    *_lowerCamelCase						,    **_lowerCamelCase							)							)
         UpperCamelCase_:      str					   =       out['name'][len(self.local_root_dir							) :]
         return out





       def     _a					(      self						,    _lowerCamelCase						,    _lowerCamelCase						,    *_lowerCamelCase						,    **_lowerCamelCase							):
         UpperCamelCase_:      Optional[int]					   =       posixpath.join(self.local_root_dir						,    self._strip_protocol(_lowerCamelCase							)							)
         UpperCamelCase_:      List[str]					   =       posixpath.join(self.local_root_dir						,    self._strip_protocol(_lowerCamelCase							)							)
         return self._fs.cp_file(_lowerCamelCase						,    _lowerCamelCase						,    *_lowerCamelCase						,    **_lowerCamelCase							)





       def     _a					(      self						,    _lowerCamelCase						,    *_lowerCamelCase						,    **_lowerCamelCase							):
         UpperCamelCase_:      Any					   =       posixpath.join(self.local_root_dir						,    self._strip_protocol(_lowerCamelCase							)							)
         return self._fs.rm_file(_lowerCamelCase						,    *_lowerCamelCase						,    **_lowerCamelCase							)





       def     _a					(      self						,    _lowerCamelCase						,    *_lowerCamelCase						,    **_lowerCamelCase							):
         UpperCamelCase_:      List[str]					   =       posixpath.join(self.local_root_dir						,    self._strip_protocol(_lowerCamelCase							)							)
         return self._fs.rm(_lowerCamelCase						,    *_lowerCamelCase						,    **_lowerCamelCase							)





       def     _a					(      self						,    _lowerCamelCase						,    *_lowerCamelCase						,    **_lowerCamelCase							):
         UpperCamelCase_:      List[Any]					   =       posixpath.join(self.local_root_dir						,    self._strip_protocol(_lowerCamelCase							)							)
         return self._fs._open(_lowerCamelCase						,    *_lowerCamelCase						,    **_lowerCamelCase							)





       def     _a					(      self						,    _lowerCamelCase							):
         UpperCamelCase_:      int					   =       posixpath.join(self.local_root_dir						,    self._strip_protocol(_lowerCamelCase							)							)
         return self._fs.created(_lowerCamelCase							)





       def     _a					(      self						,    _lowerCamelCase							):
         UpperCamelCase_:      str					   =       posixpath.join(self.local_root_dir						,    self._strip_protocol(_lowerCamelCase							)							)
         return self._fs.modified(_lowerCamelCase							)





       @classmethod
       def     _a					(      cls						,    _lowerCamelCase							):
         UpperCamelCase_:      str					   =       stringify_path(_lowerCamelCase							)
         if path.startswith('mock://'							):
           UpperCamelCase_:      str					   =       path[7:]
         return path







class        _lowerCAmelCase( __lowerCamelCase      ):





       """simple docstring"""







       a       :	Optional[int]								='tmp'
       a       :	List[Any]								=None





       def __init__(      self						,    *_lowerCamelCase						,    **_lowerCamelCase							):
         assert self.tmp_dir is not None, "TmpDirFileSystem.tmp_dir is not set"
         super().__init__(*_lowerCamelCase						,    **_lowerCamelCase						,    local_root_dir=self.tmp_dir						,    auto_mkdir=_lowerCamelCase							)





       @classmethod
       def     _a					(      cls						,    _lowerCamelCase							):
         UpperCamelCase_:      Tuple					   =       stringify_path(_lowerCamelCase							)
         if path.startswith('tmp://'							):
           UpperCamelCase_:      List[str]					   =       path[6:]
         return path







@pytest.fixture
def 						snake_case      () ->       Optional[int]:
  UpperCamelCase_:      List[str]					   =       MockFileSystem
  UpperCamelCase_:      List[Any]					   =       TmpDirFileSystem
  yield
  del _fsspec_registry["mock"]
  del _fsspec_registry["tmp"]

@pytest.fixture
def 						snake_case      (UpperCAmelCase__			,					UpperCAmelCase__						) ->       Tuple:
  UpperCamelCase_:      Union[str, Any]					   =       tmp_path_factory.mktemp('mockfs'						)
  return MockFileSystem(local_root_dir=UpperCAmelCase__			,					auto_mkdir=UpperCAmelCase__						)

@pytest.fixture
def 						snake_case      (UpperCAmelCase__			,					UpperCAmelCase__						) ->       str:
  UpperCamelCase_:      Dict					   =       tmp_path_factory.mktemp('tmpfs'						)
  with patch.object(UpperCAmelCase__			,					'tmp_dir'			,					UpperCAmelCase__						):
    yield TmpDirFileSystem()













from collections import deque

def 						snake_case      (UpperCAmelCase__						) ->       Any:
  return input(UpperCAmelCase__						).strip().split(' '						)

def 						snake_case      (UpperCAmelCase__			,					UpperCAmelCase__						) ->       dict[int, list[int]]:
  UpperCamelCase_:      dict[int, list[int]]					   =       {}
  for i in range(UpperCAmelCase__						):
    UpperCamelCase_:      str					   =       []

  for e in range(UpperCAmelCase__						):
    UpperCamelCase_   ,UpperCamelCase_:      List[Any]					   =       (int(UpperCAmelCase__						) for i in _input(F'''Edge {e + 1}: <node1> <node2> '''						))
    graph[x].append(UpperCAmelCase__						)
  return graph

def 						snake_case      (UpperCAmelCase__			,					UpperCAmelCase__						) ->       dict[int, list[int]]:
  UpperCamelCase_:      dict[int, list[int]]					   =       {}
  for i in range(UpperCAmelCase__						):
    UpperCamelCase_:      Tuple					   =       []

  for e in range(UpperCAmelCase__						):
    UpperCamelCase_   ,UpperCamelCase_:      str					   =       (int(UpperCAmelCase__						) for i in _input(F'''Edge {e + 1}: <node1> <node2> '''						))
    graph[x].append(UpperCAmelCase__						)
    graph[y].append(UpperCAmelCase__						)
  return graph

def 						snake_case      (UpperCAmelCase__			,					UpperCAmelCase__						) ->       dict[int, list[tuple[int, int]]]:
  UpperCamelCase_:      dict[int, list[tuple[int, int]]]					   =       {}
  for i in range(UpperCAmelCase__						):
    UpperCamelCase_:      List[Any]					   =       []

  for e in range(UpperCAmelCase__						):
    UpperCamelCase_   ,UpperCamelCase_   ,UpperCamelCase_:      List[str]					   =       (int(UpperCAmelCase__						) 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__":
   A_			,				A_	:	str				=				(int(i) for i in _input('Number of nodes and edges: '))

   A_	:	str				=				int(
       _input(
           'Press 1 or 2 or 3 \n'
           '1. Unweighted directed \n'
           '2. Unweighted undirected \n'
           '3. Weighted undirected \n'
       )[0]
   )

   A_	:	List[str]				=				{
       1: initialize_unweighted_directed_graph,
       2: initialize_unweighted_undirected_graph,
       3: initialize_weighted_undirected_graph,
   }[graph_choice](n, m)

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

def 						snake_case      (UpperCAmelCase__			,					UpperCAmelCase__						) ->       Dict:
  UpperCamelCase_   ,UpperCamelCase_:      int					   =       {s}, deque([s]						)
  print(UpperCAmelCase__						)
  while q:
    UpperCamelCase_:      Dict					   =       q.popleft()
    for v in g[u]:
      if v not in vis:
        vis.add(UpperCAmelCase__						)
        q.append(UpperCAmelCase__						)
        print(UpperCAmelCase__						)

def 						snake_case      (UpperCAmelCase__			,					UpperCAmelCase__						) ->       int:
  UpperCamelCase_   ,UpperCamelCase_   ,UpperCamelCase_:      Any					   =       {s: 0}, set(), {s: 0}
  while True:
    if len(UpperCAmelCase__						) == len(UpperCAmelCase__						) - 1:
      break
    UpperCamelCase_:      str					   =       1_0_0_0_0_0
    for i in dist:
      if i not in known and dist[i] < mini:
        UpperCamelCase_:      Dict					   =       dist[i]
        UpperCamelCase_:      str					   =       i
    known.add(UpperCAmelCase__						)
    for v in g[u]:
      if v[0] not in known and dist[u] + v[1] < dist.get(v[0]			,					1_0_0_0_0_0						):
        UpperCamelCase_:      Optional[Any]					   =       dist[u] + v[1]
        UpperCamelCase_:      str					   =       u
  for i in dist:
    if i != s:
      print(dist[i]						)

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

def 						snake_case      () ->       str:
  UpperCamelCase_:      Dict					   =       input().strip()
  UpperCamelCase_:      List[str]					   =       []
  for _ in range(UpperCAmelCase__						):
    a.append(map(UpperCAmelCase__			,					input().strip().split()						)						)
  return a, n

def 						snake_case      (UpperCAmelCase__						) ->       Union[str, Any]:
  ((UpperCamelCase_)   ,(UpperCamelCase_)):      Dict					   =       a_and_n
  UpperCamelCase_:      List[str]					   =       list(UpperCAmelCase__						)
  UpperCamelCase_:      int					   =       [[0] * n for i in range(UpperCAmelCase__						)]
  for k in range(UpperCAmelCase__						):
    for i in range(UpperCAmelCase__						):
      for j in range(UpperCAmelCase__						):
        if dist[i][j] > dist[i][k] + dist[k][j]:
          UpperCamelCase_:      Union[str, Any]					   =       dist[i][k] + dist[k][j]
          UpperCamelCase_:      Optional[int]					   =       k
  print(UpperCAmelCase__						)

def 						snake_case      (UpperCAmelCase__			,					UpperCAmelCase__						) ->       str:
  UpperCamelCase_   ,UpperCamelCase_   ,UpperCamelCase_:      Tuple					   =       {s: 0}, set(), {s: 0}
  while True:
    if len(UpperCAmelCase__						) == len(UpperCAmelCase__						) - 1:
      break
    UpperCamelCase_:      List[str]					   =       1_0_0_0_0_0
    for i in dist:
      if i not in known and dist[i] < mini:
        UpperCamelCase_:      Tuple					   =       dist[i]
        UpperCamelCase_:      Optional[Any]					   =       i
    known.add(UpperCAmelCase__						)
    for v in g[u]:
      if v[0] not in known and v[1] < dist.get(v[0]			,					1_0_0_0_0_0						):
        UpperCamelCase_:      Dict					   =       v[1]
        UpperCamelCase_:      Optional[Any]					   =       u
  return dist

def 						snake_case      () ->       Optional[int]:
  UpperCamelCase_   ,UpperCamelCase_:      Tuple					   =       map(UpperCAmelCase__			,					input().split(' '						)						)
  UpperCamelCase_:      List[str]					   =       []
  for _ in range(UpperCAmelCase__						):
    edges.append(map(UpperCAmelCase__			,					input().split(' '						)						)						)
  return edges, n

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

def 						snake_case      (UpperCAmelCase__						) ->       Dict:
  UpperCamelCase_:      Tuple					   =       []
  for node in graph:
    if not graph[node]:
      isolated.append(UpperCAmelCase__						)
  return isolated