

from collections import deque

def 						UpperCamelCase (lowercase_:			Dict )					->				List[Any]:
	A__							:   Optional[Any]					       =		len(lowercase_ )
	A__							:   Optional[int]					       =		deque()
	A__							:   List[str]					       =		[False for _ in range(lowercase_ )]
	A__							:   Optional[int]					       =		[-1 for _ in range(lowercase_ )]
	A__							:   Optional[int]					       =		index_of[:]

	def strong_connect(lowercase_:			List[str]   ,				lowercase_:			int   ,				lowercase_:			List[Any] ):
		A__							:   Union[str, Any]					       =		index  # the number when this node is seen
		A__							:   Any					       =		index  # lowest rank node reachable from here
		index += 1
		stack.append(lowercase_ )
		A__							:   int					       =		True

		for w in g[v]:
			if index_of[w] == -1:
				A__							:   Tuple					       =		strong_connect(lowercase_   ,				lowercase_   ,				lowercase_ )
				A__							:   str					       =		(
				    lowlink_of[w] if lowlink_of[w] < lowlink_of[v] else lowlink_of[v]
				)
			elif on_stack[w]:
				A__							:   Optional[int]					       =		(
				    lowlink_of[w] if lowlink_of[w] < lowlink_of[v] else lowlink_of[v]
				)

		if lowlink_of[v] == index_of[v]:
			A__							:   Dict					       =		[]
			A__							:   Any					       =		stack.pop()
			A__							:   List[Any]					       =		False
			component.append(lowercase_ )
			while w != v:
				A__							:   List[str]					       =		stack.pop()
				A__							:   Tuple					       =		False
				component.append(lowercase_ )
			components.append(lowercase_ )
		return index

	A__							:   List[Any]					       =		[]
	for v in range(lowercase_ ):
		if index_of[v] == -1:
			strong_connect(lowercase_   ,				0   ,				lowercase_ )

	return components

def 						UpperCamelCase (lowercase_:			Any   ,				lowercase_:			Optional[int] )					->				Dict:
	A__							:   str					       =		[[] for _ in range(lowercase_ )]
	for u, v in edges:
		g[u].append(lowercase_ )
	return g


if __name__ == "__main__":
	# Test
	A_	:			Optional[Any]  	=      7
	A_	:			Tuple  	=      [0, 0, 1, 2, 3, 3, 4, 4, 6]
	A_	:			Tuple  	=      [1, 3, 2, 0, 1, 4, 5, 6, 5]
	A_	:			Dict  	=      [(u, v) for u, v in zip(source, target)]
	A_	:			int  	=      create_graph(n_vertices, edges)

	assert [[5], [6], [4], [3, 2, 1, 0]] == tarjan(g)






from queue import PriorityQueue
from typing import Any

import numpy as np

def 						UpperCamelCase (lowercase_:			dict   ,				lowercase_:			str   ,				lowercase_:			set   ,				lowercase_:			set   ,				lowercase_:			dict   ,				lowercase_:			dict   ,				lowercase_:			PriorityQueue   ,				lowercase_:			dict   ,				lowercase_:			float | int   ,				)					->				float | int:
	for nxt, d in graph[v]:
		if nxt in visited_forward:
			continue
		A__							:   Any					       =		cst_fwd.get(lowercase_   ,				np.inf )
		A__							:   List[Any]					       =		cst_fwd[v] + d
		if new_cost_f < old_cost_f:
			queue.put((new_cost_f, nxt) )
			A__							:   Tuple					       =		new_cost_f
			A__							:   Any					       =		v
		if nxt in visited_backward:
			if cst_fwd[v] + d + cst_bwd[nxt] < shortest_distance:
				A__							:   Optional[int]					       =		cst_fwd[v] + d + cst_bwd[nxt]
	return shortest_distance

def 						UpperCamelCase (lowercase_:			str   ,				lowercase_:			str   ,				lowercase_:			dict   ,				lowercase_:			dict )					->				int:
	A__							:   Dict					       =		-1

	A__							:   List[Any]					       =		set()
	A__							:   Union[str, Any]					       =		set()
	A__							:   Optional[Any]					       =		{source: 0}
	A__							:   int					       =		{destination: 0}
	A__							:   Optional[Any]					       =		{source: None}
	A__							:   Union[str, Any]					       =		{destination: None}
	A__							:   PriorityQueue[Any]					       =		PriorityQueue()
	A__							:   PriorityQueue[Any]					       =		PriorityQueue()

	A__							:   List[Any]					       =		np.inf

	queue_forward.put((0, source) )
	queue_backward.put((0, destination) )

	if source == destination:
		return 0

	while not queue_forward.empty() and not queue_backward.empty():
		A__       ,       A__							:   Tuple					       =		queue_forward.get()
		visited_forward.add(lowercase_ )

		A__       ,       A__							:   Optional[Any]					       =		queue_backward.get()
		visited_backward.add(lowercase_ )

		A__							:   List[Any]					       =		pass_and_relaxation(
		    lowercase_   ,				lowercase_   ,				lowercase_   ,				lowercase_   ,				lowercase_   ,				lowercase_   ,				lowercase_   ,				lowercase_   ,				lowercase_   ,				)

		A__							:   List[Any]					       =		pass_and_relaxation(
		    lowercase_   ,				lowercase_   ,				lowercase_   ,				lowercase_   ,				lowercase_   ,				lowercase_   ,				lowercase_   ,				lowercase_   ,				lowercase_   ,				)

		if cst_fwd[v_fwd] + cst_bwd[v_bwd] >= shortest_distance:
			break

	if shortest_distance != np.inf:
		A__							:   int					       =		shortest_distance
	return shortest_path_distance


A_	:			List[Any]  	=      {
    'B': [['C', 1]],
    'C': [['D', 1]],
    'D': [['F', 1]],
    'E': [['B', 1], ['G', 2]],
    'F': [],
    'G': [['F', 1]],
}
A_	:			Optional[int]  	=      {
    'B': [['E', 1]],
    'C': [['B', 1]],
    'D': [['C', 1]],
    'F': [['D', 1], ['G', 1]],
    'E': [[None, np.inf]],
    'G': [['E', 2]],
}

if __name__ == "__main__":
	import doctest

	doctest.testmod()



