

'''simple docstring'''
from collections import deque


def       a__    (  _SCREAMING_SNAKE_CASE					:    Union[str, Any]							)			-> Dict:


	"""simple docstring"""





	return input(_SCREAMING_SNAKE_CASE							).strip().split(" "							)


def       a__    (  _SCREAMING_SNAKE_CASE					:    int     ,							_SCREAMING_SNAKE_CASE					:    int							)			-> dict[int, list[int]]:


	"""simple docstring"""





	UpperCAmelCase_			:	dict[int, list[int]]      =   {}
	for i in range(_SCREAMING_SNAKE_CASE							):
		UpperCAmelCase_			:	Tuple      =   []

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


def       a__    (  _SCREAMING_SNAKE_CASE					:    int     ,							_SCREAMING_SNAKE_CASE					:    int							)			-> dict[int, list[int]]:


	"""simple docstring"""





	UpperCAmelCase_			:	dict[int, list[int]]      =   {}
	for i in range(_SCREAMING_SNAKE_CASE							):
		UpperCAmelCase_			:	Optional[int]      =   []

	for e in range(_SCREAMING_SNAKE_CASE							):
		UpperCAmelCase_ , UpperCAmelCase_			:	int      =   (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       a__    (  _SCREAMING_SNAKE_CASE					:    int     ,							_SCREAMING_SNAKE_CASE					:    int							)			-> dict[int, list[tuple[int, int]]]:


	"""simple docstring"""





	UpperCAmelCase_			:	dict[int, list[tuple[int, int]]]      =   {}
	for i in range(_SCREAMING_SNAKE_CASE							):
		UpperCAmelCase_			:	int      =   []

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

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

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


def       a__    (  _SCREAMING_SNAKE_CASE					:    Tuple     ,							_SCREAMING_SNAKE_CASE					:    Optional[Any]							)			-> Tuple:


	"""simple docstring"""





	UpperCAmelCase_ , UpperCAmelCase_			:	Dict      =   {s}, [s]
	print(_SCREAMING_SNAKE_CASE							)
	while _s:
		UpperCAmelCase_			:	Optional[int]      =   0
		for i in g[_s[-1]]:
			if i not in vis:
				_s.append(_SCREAMING_SNAKE_CASE							)
				vis.add(_SCREAMING_SNAKE_CASE							)
				UpperCAmelCase_			:	Any      =   1
				print(_SCREAMING_SNAKE_CASE							)
				break
		if not flag:
			_s.pop()


def       a__    (  _SCREAMING_SNAKE_CASE					:    int     ,							_SCREAMING_SNAKE_CASE					:    Tuple							)			-> List[str]:


	"""simple docstring"""





	UpperCAmelCase_ , UpperCAmelCase_			:	List[Any]      =   {s}, deque([s]							)
	print(_SCREAMING_SNAKE_CASE							)
	while q:
		UpperCAmelCase_			:	List[Any]      =   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       a__    (  _SCREAMING_SNAKE_CASE					:    Tuple     ,							_SCREAMING_SNAKE_CASE					:    List[str]							)			-> List[str]:


	"""simple docstring"""





	UpperCAmelCase_ , UpperCAmelCase_ , UpperCAmelCase_			:	str      =   {s: 0}, set(), {s: 0}
	while True:
		if len(_SCREAMING_SNAKE_CASE							) == len(_SCREAMING_SNAKE_CASE							) - 1:
			break
		UpperCAmelCase_			:	Dict      =   10_00_00
		for i in dist:
			if i not in known and dist[i] < mini:
				UpperCAmelCase_			:	int      =   dist[i]
				UpperCAmelCase_			:	Optional[int]      =   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]     ,							10_00_00							):
				UpperCAmelCase_			:	List[str]      =   dist[u] + v[1]
				UpperCAmelCase_			:	str      =   u
	for i in dist:
		if i != s:
			print(dist[i]							)


def       a__    (  _SCREAMING_SNAKE_CASE					:    Any     ,							_SCREAMING_SNAKE_CASE					:    str=None     ,							_SCREAMING_SNAKE_CASE					:    Any=None							)			-> Dict:


	"""simple docstring"""





	if q is None:
		UpperCAmelCase_			:	Union[str, Any]      =   [1]
	if ind is None:
		UpperCAmelCase_			:	Union[str, Any]      =   [0] * (len(_SCREAMING_SNAKE_CASE							) + 1)  # SInce oth Index is ignored
		for u in g:
			for v in g[u]:
				ind[v] += 1
		UpperCAmelCase_			:	Tuple      =   deque()
		for i in g:
			if ind[i] == 0:
				q.append(_SCREAMING_SNAKE_CASE							)
	if len(_SCREAMING_SNAKE_CASE							) == 0:
		return
	UpperCAmelCase_			:	Optional[Any]      =   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       a__    (  )			-> str:


	"""simple docstring"""





	UpperCAmelCase_			:	List[str]      =   input().strip()
	UpperCAmelCase_			:	Optional[int]      =   []
	for _ in range(_SCREAMING_SNAKE_CASE							):
		a.append(map(_SCREAMING_SNAKE_CASE     ,							input().strip().split()							)							)
	return a, n


def       a__    (  _SCREAMING_SNAKE_CASE					:    List[Any]							)			-> Union[str, Any]:


	"""simple docstring"""





	((UpperCAmelCase_) , (UpperCAmelCase_))			:	List[str]      =   a_and_n
	UpperCAmelCase_			:	Optional[int]      =   list(_SCREAMING_SNAKE_CASE							)
	UpperCAmelCase_			:	List[Any]      =   [[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]:
					UpperCAmelCase_			:	List[str]      =   dist[i][k] + dist[k][j]
					UpperCAmelCase_			:	Union[str, Any]      =   k
	print(_SCREAMING_SNAKE_CASE							)


def       a__    (  _SCREAMING_SNAKE_CASE					:    str     ,							_SCREAMING_SNAKE_CASE					:    Dict							)			-> Optional[Any]:


	"""simple docstring"""





	UpperCAmelCase_ , UpperCAmelCase_ , UpperCAmelCase_			:	Tuple      =   {s: 0}, set(), {s: 0}
	while True:
		if len(_SCREAMING_SNAKE_CASE							) == len(_SCREAMING_SNAKE_CASE							) - 1:
			break
		UpperCAmelCase_			:	Any      =   10_00_00
		for i in dist:
			if i not in known and dist[i] < mini:
				UpperCAmelCase_			:	int      =   dist[i]
				UpperCAmelCase_			:	str      =   i
		known.add(_SCREAMING_SNAKE_CASE							)
		for v in g[u]:
			if v[0] not in known and v[1] < dist.get(v[0]     ,							10_00_00							):
				UpperCAmelCase_			:	str      =   v[1]
				UpperCAmelCase_			:	Optional[Any]      =   u
	return dist


def       a__    (  )			-> List[str]:


	"""simple docstring"""





	UpperCAmelCase_ , UpperCAmelCase_			:	Union[str, Any]      =   map(_SCREAMING_SNAKE_CASE     ,							input().split(" "							)							)
	UpperCAmelCase_			:	Optional[int]      =   []
	for _ in range(_SCREAMING_SNAKE_CASE							):
		edges.append(map(_SCREAMING_SNAKE_CASE     ,							input().split(" "							)							)							)
	return edges, n


def       a__    (  _SCREAMING_SNAKE_CASE					:    int							)			-> Dict:


	"""simple docstring"""





	((UpperCAmelCase_) , (UpperCAmelCase_))			:	Any      =   e_and_n
	e.sort(reverse=_SCREAMING_SNAKE_CASE     ,							key=lambda _SCREAMING_SNAKE_CASE							: x[2]							)
	UpperCAmelCase_			:	List[Any]      =   [{i} for i in range(1     ,							n + 1							)]
	while True:
		if len(_SCREAMING_SNAKE_CASE							) == 1:
			break
		print(_SCREAMING_SNAKE_CASE							)
		UpperCAmelCase_			:	Dict      =   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       a__    (  _SCREAMING_SNAKE_CASE					:    Any							)			-> Tuple:


	"""simple docstring"""





	UpperCAmelCase_			:	Tuple      =   []
	for node in graph:
		if not graph[node]:
			isolated.append(_SCREAMING_SNAKE_CASE							)
	return isolated







'''simple docstring'''
from transformers import PretrainedConfig
class  _snake_case						(__SCREAMING_SNAKE_CASE):
			__A   :     Optional[Any]          ="custom"






			def __init__(   self       ,_snake_case=1       ,**_snake_case			):
				UpperCAmelCase_			:	Optional[int]      =   attribute
				super().__init__(**_snake_case			)




class  _snake_case						(__SCREAMING_SNAKE_CASE):
			__A   :     Dict          ="custom"






			def __init__(   self       ,_snake_case=1       ,**_snake_case			):
				UpperCAmelCase_			:	Optional[int]      =   attribute




