




from collections import deque





def 							A__   (snake_case      :		Any							)    ->	Tuple:
					return input(snake_case							).strip().split(""" """							)





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

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





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

					for e in range(snake_case							):
										__UpperCamelCase				:  List[str]								=			(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 							A__   (snake_case      :		int		,  snake_case      :		int							)    ->	dict[int, list[tuple[int, int]]]:
					__UpperCamelCase				:  dict[int, list[tuple[int, int]]]								=			{}
					for i in range(snake_case							):
										__UpperCamelCase				:  Optional[Any]								=			[]

					for e in range(snake_case							):
										__UpperCamelCase				:  Tuple								=			(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__":
	a__    ,       a__		    =    (int(i) for i in _input('''Number of nodes and edges: '''))

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

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





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





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





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





def 							A__   (snake_case      :		List[Any]		,  snake_case      :		Union[str, Any]=None		,  snake_case      :		Any=None							)    ->	int:
					if q is None:
										__UpperCamelCase				:  int								=			[1]
					if ind is None:
										__UpperCamelCase				:  Optional[int]								=			[0] * (len(snake_case							) + 1)  # SInce oth Index is ignored
										for u in g:
															for v in g[u]:
																				ind[v] += 1
										__UpperCamelCase				:  Any								=			deque()
										for i in g:
															if ind[i] == 0:
																				q.append(snake_case							)
					if len(snake_case							) == 0:
										return
					__UpperCamelCase				:  Optional[int]								=			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 							A__   ()    ->	Any:
					__UpperCamelCase				:  List[Any]								=			input().strip()
					__UpperCamelCase				:  List[str]								=			[]
					for _ in range(snake_case							):
										a.append(map(snake_case		,  input().strip().split()							)							)
					return a, n





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





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





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





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












a__		    =    {
    "kilogram": 1,
    "gram": pow(10, 3),
    "milligram": pow(10, 6),
    "metric-ton": pow(10, -3),
    "long-ton": 0.00_0984_2073,
    "short-ton": 0.00_1102_3122,
    "pound": 2.20_4624_4202,
    "stone": 0.15_7473_1728,
    "ounce": 35.2_7399_0723,
    "carrat": 5000,
    "atomic-mass-unit": 6.0_2213_6652e26,
}

a__		    =    {
    "kilogram": 1,
    "gram": pow(10, -3),
    "milligram": pow(10, -6),
    "metric-ton": pow(10, 3),
    "long-ton": 1016.0_4608,
    "short-ton": 907.184,
    "pound": 0.45_3592,
    "stone": 6.3_5029,
    "ounce": 0.028_3495,
    "carrat": 0.0002,
    "atomic-mass-unit": 1.6_6054_0199e-27,
}





def 							A__   (snake_case      :		str		,  snake_case      :		str		,  snake_case      :		float							)    ->	float:
					if to_type not in KILOGRAM_CHART or from_type not in WEIGHT_TYPE_CHART:
										__UpperCamelCase				:  Any								=			(
										    F'''Invalid \'from_type\' or \'to_type\' value: {from_type!r}, {to_type!r}\n'''
										    F'''Supported values are: {", ".join(snake_case							)}'''
										)
										raise ValueError(snake_case							)
					return value * KILOGRAM_CHART[to_type] * WEIGHT_TYPE_CHART[from_type]


if __name__ == "__main__":
	import doctest

	doctest.testmod()






