






"""simple docstring"""





from heapq import heappop, heappush

import numpy as np



def   a    (     __UpperCAmelCase      :    np.ndarray      ,   __UpperCAmelCase      :    tuple[int, int]      ,   __UpperCAmelCase      :    tuple[int, int]      ,   __UpperCAmelCase      :    bool      ,   )    ->							tuple[float | int, list[tuple[int, int]]]:
						__magic_name__,			__magic_name__:	Dict							=       grid.shape
						__magic_name__:	Optional[Any]							=       [-1, 1, 0, 0]
						__magic_name__:	int							=       [0, 0, -1, 1]
						if allow_diagonal:
												dx += [-1, -1, 1, 1]
												dy += [-1, 1, -1, 1]

						__magic_name__,			__magic_name__:	Any							=       [(0, source)], set()
						__magic_name__:	Optional[int]							=       np.full((rows, cols)      ,   np.inf  )
						__magic_name__:	int							=       0
						__magic_name__:	Tuple							=       np.empty((rows, cols)      ,   dtype=__UpperCAmelCase  )
						__magic_name__:	List[Any]							=       None

						while queue:
												((__magic_name__),			(__magic_name__)):	str							=       heappop(__UpperCAmelCase  )
												if (x, y) in visited:
																		continue
												visited.add((x, y)  )

												if (x, y) == destination:
																		__magic_name__:	Tuple							=       []
																		while (x, y) != source:
																								path.append((x, y)  )
																								__magic_name__,			__magic_name__:	Union[str, Any]							=       predecessors[x, y]
																		path.append(__UpperCAmelCase  )  # add the source manually
																		path.reverse()
																		return matrix[destination], path

												for i in range(len(__UpperCAmelCase  )  ):
																		__magic_name__,			__magic_name__:	List[Any]							=       x + dx[i], y + dy[i]
																		if 0 <= nx < rows and 0 <= ny < cols:
																								__magic_name__:	str							=       grid[nx][ny]
																								if next_node == 1 and matrix[nx, ny] > dist + 1:
																														heappush(__UpperCAmelCase      ,   (dist + 1, (nx, ny))  )
																														__magic_name__:	Union[str, Any]							=       dist + 1
																														__magic_name__:	Dict							=       (x, y)

						return np.inf, []


if __name__ == "__main__":
							import doctest

							doctest.testmod()











"""simple docstring"""





def   a    (     __UpperCAmelCase      :    List[Any]  )    ->							str:
						__magic_name__:	Optional[int]							=       [0] * len(__UpperCAmelCase  )
						__magic_name__:	str							=       []
						__magic_name__:	Any							=       []
						__magic_name__:	Union[str, Any]							=       0

						for values in graph.values():
												for i in values:
																		indegree[i] += 1

						for i in range(len(__UpperCAmelCase  )  ):
												if indegree[i] == 0:
																		queue.append(__UpperCAmelCase  )

						while queue:
												__magic_name__:	Optional[Any]							=       queue.pop(0  )
												cnt += 1
												topo.append(__UpperCAmelCase  )
												for x in graph[vertex]:
																		indegree[x] -= 1
																		if indegree[x] == 0:
																								queue.append(__UpperCAmelCase  )

						if cnt != len(__UpperCAmelCase  ):
												print("""Cycle exists"""  )
						else:
												print(__UpperCAmelCase  )


# Adjacency List of Graph
__lowerCamelCase							=  {0: [1, 2], 1: [3], 2: [3], 3: [4, 5], 4: [], 5: []}

topological_sort(graph)



