



from queue import PriorityQueue
from typing import Any

import numpy as np






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






def lowerCamelCase__   (							snake_case_     :  str	,				snake_case_     :  str	,				snake_case_     :  dict	,				snake_case_     :  dict	)				->    int:
   __snake_case								=       -1

   __snake_case								=       set()
   __snake_case								=       set()
   __snake_case								=       {source: 0}
   __snake_case								=       {destination: 0}
   __snake_case								=       {source: None}
   __snake_case								=       {destination: None}
   __snake_case								=       PriorityQueue()
   __snake_case								=       PriorityQueue()

   __snake_case								=       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():
      __snake_case	,     __snake_case								=       queue_forward.get()
      visited_forward.add(snake_case_	)

      __snake_case	,     __snake_case								=       queue_backward.get()
      visited_backward.add(snake_case_	)

      __snake_case								=       pass_and_relaxation(
          snake_case_	,				snake_case_	,				snake_case_	,				snake_case_	,				snake_case_	,				snake_case_	,				snake_case_	,				snake_case_	,				snake_case_	,				)

      __snake_case								=       pass_and_relaxation(
          snake_case_	,				snake_case_	,				snake_case_	,				snake_case_	,				snake_case_	,				snake_case_	,				snake_case_	,				snake_case_	,				snake_case_	,				)

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

   if shortest_distance != np.inf:
      __snake_case								=       shortest_distance
   return shortest_path_distance


snake_case_           =      {
    'B': [['C', 1]],
    'C': [['D', 1]],
    'D': [['F', 1]],
    'E': [['B', 1], ['G', 2]],
    'F': [],
    'G': [['F', 1]],
}
snake_case_           =      {
    '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()








class 		SCREAMING_SNAKE_CASE__    :


      def __init__(self	:				str    ,      a__	:				list				):





         """simple docstring"""



         __snake_case								=       set_counts
         __snake_case								=       max(a__				)
         __snake_case								=       len(a__				)
         __snake_case								=       [1] * num_sets
         __snake_case								=       list(range(a__				)				)


      def        a			(self	:				str    ,      a__	:				int    ,      a__	:				int				):





         """simple docstring"""



         __snake_case								=       self.get_parent(a__				)
         __snake_case								=       self.get_parent(a__				)

         if src_parent == dst_parent:
            return False

         if self.ranks[dst_parent] >= self.ranks[src_parent]:
            self.set_counts[dst_parent] += self.set_counts[src_parent]
            __snake_case								=       0
            __snake_case								=       dst_parent
            if self.ranks[dst_parent] == self.ranks[src_parent]:
               self.ranks[dst_parent] += 1
            __snake_case								=       self.set_counts[dst_parent]
         else:
            self.set_counts[src_parent] += self.set_counts[dst_parent]
            __snake_case								=       0
            __snake_case								=       src_parent
            __snake_case								=       self.set_counts[src_parent]

         __snake_case								=       max(self.max_set    ,      a__				)
         return True


      def        a			(self	:				Union[str, Any]    ,      a__	:				int				):





         """simple docstring"""



         if self.parents[disj_set] == disj_set:
            return disj_set
         __snake_case								=       self.get_parent(self.parents[disj_set]				)
         return self.parents[disj_set]

