

'''simple docstring'''







from collections import deque






def 					_SCREAMING_SNAKE_CASE		(						snake_case_	):
	return input(snake_case_	).strip().split(""" """	)






def 					_SCREAMING_SNAKE_CASE		(						snake_case_							,       snake_case_	):
	_lowercase							=     {}
	for i in range(snake_case_	):
		_lowercase							=     []

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






def 					_SCREAMING_SNAKE_CASE		(						snake_case_							,       snake_case_	):
	_lowercase							=     {}
	for i in range(snake_case_	):
		_lowercase							=     []

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






def 					_SCREAMING_SNAKE_CASE		(						snake_case_							,       snake_case_	):
	_lowercase							=     {}
	for i in range(snake_case_	):
		_lowercase							=     []

	for e in range(snake_case_	):
		_lowercase		,		_lowercase		,		_lowercase							=     (int(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    =  (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 					_SCREAMING_SNAKE_CASE		(						snake_case_							,       snake_case_	):
	_lowercase		,		_lowercase							=     {s}, [s]
	print(snake_case_	)
	while _s:
		_lowercase							=     0
		for i in g[_s[-1]]:
			if i not in vis:
				_s.append(snake_case_	)
				vis.add(snake_case_	)
				_lowercase							=     1
				print(snake_case_	)
				break
		if not flag:
			_s.pop()






def 					_SCREAMING_SNAKE_CASE		(						snake_case_							,       snake_case_	):
	_lowercase		,		_lowercase							=     {s}, deque([s]	)
	print(snake_case_	)
	while q:
		_lowercase							=     q.popleft()
		for v in g[u]:
			if v not in vis:
				vis.add(snake_case_	)
				q.append(snake_case_	)
				print(snake_case_	)






def 					_SCREAMING_SNAKE_CASE		(						snake_case_							,       snake_case_	):
	_lowercase		,		_lowercase		,		_lowercase							=     {s: 0}, set(), {s: 0}
	while True:
		if len(snake_case_	) == len(snake_case_	) - 1:
			break
		_lowercase							=     100000
		for i in dist:
			if i not in known and dist[i] < mini:
				_lowercase							=     dist[i]
				_lowercase							=     i
		known.add(snake_case_	)
		for v in g[u]:
			if v[0] not in known and dist[u] + v[1] < dist.get(v[0]							,       100000	):
				_lowercase							=     dist[u] + v[1]
				_lowercase							=     u
	for i in dist:
		if i != s:
			print(dist[i]	)






def 					_SCREAMING_SNAKE_CASE		(						snake_case_							,       snake_case_=None							,       snake_case_=None	):





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






def 					_SCREAMING_SNAKE_CASE		(						):
	_lowercase							=     input().strip()
	_lowercase							=     []
	for _ in range(snake_case_	):
		a.append(map(snake_case_							,       input().strip().split()	)	)
	return a, n






def 					_SCREAMING_SNAKE_CASE		(						snake_case_	):
	((_lowercase)		,		(_lowercase))							=     a_and_n
	_lowercase							=     list(snake_case_	)
	_lowercase							=     [[0] * n for i in range(snake_case_	)]
	for k in range(snake_case_	):
		for i in range(snake_case_	):
			for j in range(snake_case_	):
				if dist[i][j] > dist[i][k] + dist[k][j]:
					_lowercase							=     dist[i][k] + dist[k][j]
					_lowercase							=     k
	print(snake_case_	)






def 					_SCREAMING_SNAKE_CASE		(						snake_case_							,       snake_case_	):
	_lowercase		,		_lowercase		,		_lowercase							=     {s: 0}, set(), {s: 0}
	while True:
		if len(snake_case_	) == len(snake_case_	) - 1:
			break
		_lowercase							=     100000
		for i in dist:
			if i not in known and dist[i] < mini:
				_lowercase							=     dist[i]
				_lowercase							=     i
		known.add(snake_case_	)
		for v in g[u]:
			if v[0] not in known and v[1] < dist.get(v[0]							,       100000	):
				_lowercase							=     v[1]
				_lowercase							=     u
	return dist






def 					_SCREAMING_SNAKE_CASE		(						):
	_lowercase		,		_lowercase							=     map(snake_case_							,       input().split(""" """	)	)
	_lowercase							=     []
	for _ in range(snake_case_	):
		edges.append(map(snake_case_							,       input().split(""" """	)	)	)
	return edges, n






def 					_SCREAMING_SNAKE_CASE		(						snake_case_	):
	((_lowercase)		,		(_lowercase))							=     e_and_n
	e.sort(reverse=snake_case_							,       key=lambda snake_case_	: x[2]	)
	_lowercase							=     [{i} for i in range(1							,       n + 1	)]
	while True:
		if len(snake_case_	) == 1:
			break
		print(snake_case_	)
		_lowercase							=     e.pop()
		for i in range(len(snake_case_	)	):
			if x[0] in s[i]:
				break
		for j in range(len(snake_case_	)	):
			if x[1] in s[j]:
				if i == j:
					break
				s[j].update(s[i]	)
				s.pop(snake_case_	)
				break






def 					_SCREAMING_SNAKE_CASE		(						snake_case_	):
	_lowercase							=     []
	for node in graph:
		if not graph[node]:
			isolated.append(snake_case_	)
	return isolated






"""simple docstring"""




import safs
class SCREAMING_SNAKE_CASE       (      safs.SaFileSystem					):






	'''simple docstring'''




