





from __future__ import annotations

__A							:			List[str]         =			{
    "A": ["B", "C", "E"],
    "B": ["A", "D", "E"],
    "C": ["A", "F", "G"],
    "D": ["B"],
    "E": ["A", "B", "D"],
    "F": ["C"],
    "G": ["C"],
}







class      lowerCamelCase:
     '''simple docstring'''


     def __init__(    self				,     snake_case_				,     snake_case_							):
         _A     =							graph
         # mapping node to its parent in resulting breadth first tree
         _A     =							{}
         _A     =							source_vertex




     def        lowerCAmelCase__		(    self							):
         _A     =							{self.source_vertex}
         _A     =							None
         _A     =							[self.source_vertex]  # first in first out queue

         while queue:
             _A     =							queue.pop(0							)
             for adjacent_vertex in self.graph[vertex]:
                 if adjacent_vertex not in visited:
                     visited.add(snake_case_							)
                     _A     =							vertex
                     queue.append(snake_case_							)




     def        lowerCAmelCase__		(    self				,     snake_case_							):
         if target_vertex == self.source_vertex:
             return self.source_vertex

         _A     =							self.parent.get(snake_case_							)
         if target_vertex_parent is None:
             _A     =							(
                 F"No path from vertex: {self.source_vertex} to vertex: {target_vertex}"
             )
             raise ValueError(snake_case_							)

         return self.shortest_path(snake_case_							) + F"->{target_vertex}"


if __name__ == "__main__":
 __A							:			Optional[int]         =			Graph(graph, "G")
 g.breath_first_search()
 print(g.shortest_path("D"))
 print(g.shortest_path("G"))
 print(g.shortest_path("Foo"))








'''simple docstring'''







from math import pow
def    UpperCAmelCase__     (   UpperCAmelCase__,							UpperCAmelCase__,							UpperCAmelCase__,							UpperCAmelCase__,							UpperCAmelCase__,							)      ->      tuple[int, int]:
       if current_sum == needed_sum:
              # If the sum of the powers is equal to needed_sum, then we have a solution.
              solutions_count += 1
              return current_sum, solutions_count

       A_						       =   int(pow(UpperCAmelCase__,							UpperCAmelCase__					)					)
       if current_sum + i_to_n <= needed_sum:
              # If the sum of the powers is less than needed_sum, then continue adding powers.
              current_sum += i_to_n
              A_       ,      A_						       =   backtrack(
                  UpperCAmelCase__,							UpperCAmelCase__,							current_number + 1,							UpperCAmelCase__,							UpperCAmelCase__					)
              current_sum -= i_to_n
       if i_to_n < needed_sum:
              # If the power of i is less than needed_sum, then try with the next power.
              A_       ,      A_						       =   backtrack(
                  UpperCAmelCase__,							UpperCAmelCase__,							current_number + 1,							UpperCAmelCase__,							UpperCAmelCase__					)
       return current_sum, solutions_count
def    UpperCAmelCase__     (   UpperCAmelCase__,							UpperCAmelCase__					)      ->      int:
       if not (1 <= needed_sum <= 10_00 and 2 <= power <= 10):
              raise ValueError(
                  """Invalid input\n"""
                  """needed_sum must be between 1 and 1000, power between 2 and 10."""					)

       return backtrack(UpperCAmelCase__,							UpperCAmelCase__,							1,							0,							0					)[1]  # Return the solutions_count


if __name__ == "__main__":
      import doctest

      doctest.testmod()
