




from collections import deque

def       SCREAMING_SNAKE_CASE							(     __UpperCamelCase)    ->  Optional[Any]:
     return input(__UpperCamelCase).strip().split(" ")

def       SCREAMING_SNAKE_CASE							(     __UpperCamelCase	,      __UpperCamelCase)    ->  dict[int, list[int]]:
     a											=   {}
     for i in range(__UpperCamelCase):
          a											=   []

     for e in range(__UpperCamelCase):
          a						,   a											=   (int(__UpperCamelCase) for i in _input(f'''Edge {e + 1}: <node1> <node2> '''))
          graph[x].append(__UpperCamelCase)
     return graph

def       SCREAMING_SNAKE_CASE							(     __UpperCamelCase	,      __UpperCamelCase)    ->  dict[int, list[int]]:
     a											=   {}
     for i in range(__UpperCamelCase):
          a											=   []

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

def       SCREAMING_SNAKE_CASE							(     __UpperCamelCase	,      __UpperCamelCase)    ->  dict[int, list[tuple[int, int]]]:
     a											=   {}
     for i in range(__UpperCamelCase):
          a											=   []

     for e in range(__UpperCamelCase):
          a						,   a						,   a											=   (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__":
   lowercase__					,       lowercase__   :    Optional[int] 					=      (int(i) for i in _input("Number of nodes and edges: "))

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

   lowercase__   :    Optional[int] 					=      {
       1: initialize_unweighted_directed_graph,
       2: initialize_unweighted_undirected_graph,
       3: initialize_weighted_undirected_graph,
   }[graph_choice](n, m)

def       SCREAMING_SNAKE_CASE							(     __UpperCamelCase	,      __UpperCamelCase)    ->  Any:
     a						,   a											=   {s}, [s]
     print(__UpperCamelCase)
     while _s:
          a											=   0
          for i in g[_s[-1]]:
               if i not in vis:
                    _s.append(__UpperCamelCase)
                    vis.add(__UpperCamelCase)
                    a											=   1
                    print(__UpperCamelCase)
                    break
          if not flag:
               _s.pop()

def       SCREAMING_SNAKE_CASE							(     __UpperCamelCase	,      __UpperCamelCase)    ->  Any:
     a						,   a											=   {s}, deque([s])
     print(__UpperCamelCase)
     while q:
          a											=   q.popleft()
          for v in g[u]:
               if v not in vis:
                    vis.add(__UpperCamelCase)
                    q.append(__UpperCamelCase)
                    print(__UpperCamelCase)

def       SCREAMING_SNAKE_CASE							(     __UpperCamelCase	,      __UpperCamelCase)    ->  Optional[int]:
     a						,   a						,   a											=   {s: 0}, set(), {s: 0}
     while True:
          if len(__UpperCamelCase) == len(__UpperCamelCase) - 1:
               break
          a											=   10_00_00
          for i in dist:
               if i not in known and dist[i] < mini:
                    a											=   dist[i]
                    a											=   i
          known.add(__UpperCamelCase)
          for v in g[u]:
               if v[0] not in known and dist[u] + v[1] < dist.get(v[0]	,      10_00_00):
                    a											=   dist[u] + v[1]
                    a											=   u
     for i in dist:
          if i != s:
               print(dist[i])

def       SCREAMING_SNAKE_CASE							(     __UpperCamelCase	,      __UpperCamelCase=None	,      __UpperCamelCase=None)    ->  Tuple:
     if q is None:
          a											=   [1]
     if ind is None:
          a											=   [0] * (len(__UpperCamelCase) + 1)  # SInce oth Index is ignored
          for u in g:
               for v in g[u]:
                    ind[v] += 1
          a											=   deque()
          for i in g:
               if ind[i] == 0:
                    q.append(__UpperCamelCase)
     if len(__UpperCamelCase) == 0:
          return
     a											=   q.popleft()
     print(__UpperCamelCase)
     for w in g[v]:
          ind[w] -= 1
          if ind[w] == 0:
               q.append(__UpperCamelCase)
     topo(__UpperCamelCase	,      __UpperCamelCase	,      __UpperCamelCase)

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

def       SCREAMING_SNAKE_CASE							(     __UpperCamelCase)    ->  Optional[Any]:
     ((a)						,   (a))											=   a_and_n
     a											=   list(__UpperCamelCase)
     a											=   [[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]:
                         a											=   dist[i][k] + dist[k][j]
                         a											=   k
     print(__UpperCamelCase)

def       SCREAMING_SNAKE_CASE							(     __UpperCamelCase	,      __UpperCamelCase)    ->  List[Any]:
     a						,   a						,   a											=   {s: 0}, set(), {s: 0}
     while True:
          if len(__UpperCamelCase) == len(__UpperCamelCase) - 1:
               break
          a											=   10_00_00
          for i in dist:
               if i not in known and dist[i] < mini:
                    a											=   dist[i]
                    a											=   i
          known.add(__UpperCamelCase)
          for v in g[u]:
               if v[0] not in known and v[1] < dist.get(v[0]	,      10_00_00):
                    a											=   v[1]
                    a											=   u
     return dist

def       SCREAMING_SNAKE_CASE							(     )    ->  Dict:
     a						,   a											=   map(__UpperCamelCase	,      input().split(" "))
     a											=   []
     for _ in range(__UpperCamelCase):
          edges.append(map(__UpperCamelCase	,      input().split(" ")))
     return edges, n

def       SCREAMING_SNAKE_CASE							(     __UpperCamelCase)    ->  Any:
     # Sort edges on the basis of distance
     ((a)						,   (a))											=   e_and_n
     e.sort(reverse=__UpperCamelCase	,      key=lambda __UpperCamelCase: x[2])
     a											=   [{i} for i in range(1	,      n + 1)]
     while True:
          if len(__UpperCamelCase) == 1:
               break
          print(__UpperCamelCase)
          a											=   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       SCREAMING_SNAKE_CASE							(     __UpperCamelCase)    ->  List[Any]:
     a											=   []
     for node in graph:
          if not graph[node]:
               isolated.append(__UpperCamelCase)
     return isolated







import safs




class     a__ (      safs.SaFileSystem   ):
     pass

