





'''simple docstring'''


from math import pow
def 							UpperCAmelCase_  (						__lowerCamelCase : Optional[Any]     ,__lowerCamelCase : Tuple     ,__lowerCamelCase : Optional[Any]     ,__lowerCamelCase : List[str]     ,__lowerCamelCase : Dict     ,):
   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

   lowercase_      :Any         =			int(pow(__lowerCAmelCase     ,__lowerCAmelCase			)			)
   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
      lowercase_      :Tuple         =			backtrack(
          __lowerCAmelCase     ,__lowerCAmelCase     ,current_number + 1     ,__lowerCAmelCase     ,__lowerCAmelCase			)
      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.
      lowercase_      :List[str]         =			backtrack(
          __lowerCAmelCase     ,__lowerCAmelCase     ,current_number + 1     ,__lowerCAmelCase     ,__lowerCAmelCase			)
   return current_sum, solutions_count
def 							UpperCAmelCase_  (						__lowerCamelCase : List[str]     ,__lowerCamelCase : List[str]			):
   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(__lowerCAmelCase     ,__lowerCAmelCase     ,1     ,0     ,0			)[1]  # Return the solutions_count


if __name__ == "__main__":
 import doctest

 doctest.testmod()









'''simple docstring'''


from __future__ import annotations

lowerCAmelCase :					Any 							={
    '''A''': ['''B''', '''C''', '''E'''],
    '''B''': ['''A''', '''D''', '''E'''],
    '''C''': ['''A''', '''F''', '''G'''],
    '''D''': ['''B'''],
    '''E''': ['''A''', '''B''', '''D'''],
    '''F''': ['''C'''],
    '''G''': ['''C'''],
}
class 				a_       :





     def __init__(			self		: List[Any]     ,				lowercase		: dict[str, list[str]]     ,				lowercase		: str						):





        """simple docstring"""




        lowercase_      :List[str]         =			graph
        # mapping node to its parent in resulting breadth first tree
        lowercase_      :dict[str, str | None]         =			{}
        lowercase_      :Dict         =			source_vertex





     def 							lowercase__				(			self		: Tuple						):





        """simple docstring"""




        lowercase_      :Union[str, Any]         =			{self.source_vertex}
        lowercase_      :Tuple         =			None
        lowercase_      :Dict         =			[self.source_vertex]  # first in first out queue

        while queue:
           lowercase_      :int         =			queue.pop(0						)
           for adjacent_vertex in self.graph[vertex]:
              if adjacent_vertex not in visited:
                 visited.add(lowercase						)
                 lowercase_      :Optional[Any]         =			vertex
                 queue.append(lowercase						)







     def 							lowercase__				(			self		: Tuple     ,				lowercase		: str						):





        """simple docstring"""




        if target_vertex == self.source_vertex:
           return self.source_vertex

        lowercase_      :List[str]         =			self.parent.get(lowercase						)
        if target_vertex_parent is None:
           lowercase_      :Union[str, Any]         =			(
               F'No path from vertex: {self.source_vertex} to vertex: {target_vertex}'
           )
           raise ValueError(lowercase						)

        return self.shortest_path(lowercase						) + F'->{target_vertex}'


if __name__ == "__main__":
 lowerCAmelCase :					Dict 							=Graph(graph, '''G''')
 g.breath_first_search()
 print(g.shortest_path('''D'''))
 print(g.shortest_path('''G'''))
 print(g.shortest_path('''Foo'''))


