





"""simple docstring"""




import math
import sys

class 					_UpperCAmelCase    :



      '''simple docstring'''

      def __init__(	self    ):

        """simple docstring"""

        A_    :			Tuple									=    0
        A_    :			List[str]									=    []
        A_    :			Any									=    {}  # To store the pos of node in array

      def    lowerCamelCase_     (	self    ):

        """simple docstring"""

        return self.cur_size == 0

      def    lowerCamelCase_     (	self   , snake_case_    ):

        """simple docstring"""

        A_    :			Optional[int]									=    self.left(snake_case_    )
        A_    :			Dict									=    self.right(snake_case_    )
        if lc < self.cur_size and self.array(snake_case_    )[0] < self.array(snake_case_    )[0]:
          A_    :			List[Any]									=    lc
        else:
          A_    :			List[Any]									=    idx
        if rc < self.cur_size and self.array(snake_case_    )[0] < self.array(snake_case_    )[0]:
          A_    :			int									=    rc
        if smallest != idx:
          self.swap(snake_case_   , snake_case_    )
          self.min_heapify(snake_case_    )

      def    lowerCamelCase_     (	self   , snake_case_    ):

        """simple docstring"""

        A_    :			str									=    self.cur_size
        self.cur_size += 1
        self.array.append((sys.maxsize, tup[1])    )
        self.decrease_key((sys.maxsize, tup[1])   , tup[0]    )

      def    lowerCamelCase_     (	self    ):

        """simple docstring"""

        A_    :			List[Any]									=    self.array[0][1]
        A_    :			List[str]									=    self.array[self.cur_size - 1]
        self.cur_size -= 1
        self.min_heapify(1    )
        del self.pos[min_node]
        return min_node

      def    lowerCamelCase_     (	self   , snake_case_    ):

        """simple docstring"""

        return 2 * i + 1

      def    lowerCamelCase_     (	self   , snake_case_    ):

        """simple docstring"""

        return 2 * i + 2

      def    lowerCamelCase_     (	self   , snake_case_    ):

        """simple docstring"""

        return math.floor(i / 2    )

      def    lowerCamelCase_     (	self   , snake_case_   , snake_case_    ):

        """simple docstring"""

        A_    :			Union[str, Any]									=    j
        A_    :			Optional[Any]									=    i
        A_    :			Union[str, Any]									=    self.array[i]
        A_    :			int									=    self.array[j]
        A_    :			Optional[Any]									=    temp

      def    lowerCamelCase_     (	self   , snake_case_   , snake_case_    ):

        """simple docstring"""

        A_    :			str									=    self.pos[tup[1]]
        # assuming the new_d is atmost old_d
        A_    :			Tuple									=    (new_d, tup[1])
        while idx > 0 and self.array[self.par(snake_case_    )][0] > self.array[idx][0]:
          self.swap(snake_case_   , self.par(snake_case_    )    )
          A_    :			Optional[int]									=    self.par(snake_case_    )


class 					_UpperCAmelCase    :



      '''simple docstring'''

      def __init__(	self   , snake_case_    ):

        """simple docstring"""

        A_    :			List[Any]									=    {}  # To store graph: u -> (v,w)
        A_    :			Dict									=    num  # Number of nodes in graph
        # To store the distance from source vertex
        A_    :			int									=    [0] * self.num_nodes
        A_    :			List[Any]									=    [-1] * self.num_nodes  # To store the path

      def    lowerCamelCase_     (	self   , snake_case_   , snake_case_   , snake_case_    ):

        """simple docstring"""

        if u in self.adjList:
          self.adjList[u].append((v, w)    )
        else:
          A_    :			Dict									=    [(v, w)]

        # Assuming undirected graph
        if v in self.adjList:
          self.adjList[v].append((u, w)    )
        else:
          A_    :			Tuple									=    [(u, w)]

      def    lowerCamelCase_     (	self    ):

        """simple docstring"""

        for u in self.adjList:
          print(snake_case_   , '->'   , ' -> '.join(str(F"""{v}({w})"""    ) for v, w in self.adjList[u]    )    )

      def    lowerCamelCase_     (	self   , snake_case_    ):

        """simple docstring"""

        A_    :			Optional[Any]									=    [-1] * self.num_nodes
        # src is the source node
        A_    :			List[str]									=    0
        A_    :			Dict									=    PriorityQueue()
        q.insert((0, src)    )  # (dist from src, node)
        for u in self.adjList:
          if u != src:
            A_    :			Optional[Any]									=    sys.maxsize  # Infinity
            A_    :			Union[str, Any]									=    -1

        while not q.is_empty():
          A_    :			List[Any]									=    q.extract_min()  # Returns node with the min dist from source
          # Update the distance of all the neighbours of u and
          # if their prev dist was INFINITY then push them in Q
          for v, w in self.adjList[u]:
            A_    :			str									=    self.dist[u] + w
            if self.dist[v] > new_dist:
              if self.dist[v] == sys.maxsize:
                q.insert((new_dist, v)    )
              else:
                q.decrease_key((self.dist[v], v)   , snake_case_    )
              A_    :			str									=    new_dist
              A_    :			str									=    u

        # Show the shortest distances from src
        self.show_distances(snake_case_    )

      def    lowerCamelCase_     (	self   , snake_case_    ):

        """simple docstring"""

        print(F"""Distance from node: {src}"""    )
        for u in range(self.num_nodes    ):
          print(F"""Node {u} has distance: {self.dist[u]}"""    )

      def    lowerCamelCase_     (	self   , snake_case_   , snake_case_    ):

        """simple docstring"""

        A_    :			Any									=    []
        A_    :			List[Any]									=    0
        A_    :			List[str]									=    dest
        # Backtracking from dest to src
        while self.par[temp] != -1:
          path.append(snake_case_    )
          if temp != src:
            for v, w in self.adjList[temp]:
              if v == self.par[temp]:
                cost += w
                break
          A_    :			Any									=    self.par[temp]
        path.append(snake_case_    )
        path.reverse()

        print(F"""----Path to reach {dest} from {src}----"""    )
        for u in path:
          print(F"""{u}"""   , end=' '    )
          if u != dest:
            print('-> '   , end=''    )

        print('\nTotal cost of path: '   , snake_case_    )


if __name__ == "__main__":
   lowerCamelCase_	:		Union[str, Any]         =   Graph(9)
   graph.add_edge(0, 1, 4)
   graph.add_edge(0, 7, 8)
   graph.add_edge(1, 2, 8)
   graph.add_edge(1, 7, 11)
   graph.add_edge(2, 3, 7)
   graph.add_edge(2, 8, 2)
   graph.add_edge(2, 5, 4)
   graph.add_edge(3, 4, 9)
   graph.add_edge(3, 5, 14)
   graph.add_edge(4, 5, 10)
   graph.add_edge(5, 6, 2)
   graph.add_edge(6, 7, 1)
   graph.add_edge(6, 8, 6)
   graph.add_edge(7, 8, 7)
   graph.show_graph()
   graph.dijkstra(0)
   graph.show_path(0, 4)

# OUTPUT
# 0 -> 1(4) -> 7(8)
# 1 -> 0(4) -> 2(8) -> 7(11)
# 7 -> 0(8) -> 1(11) -> 6(1) -> 8(7)
# 2 -> 1(8) -> 3(7) -> 8(2) -> 5(4)
# 3 -> 2(7) -> 4(9) -> 5(14)
# 8 -> 2(2) -> 6(6) -> 7(7)
# 5 -> 2(4) -> 3(14) -> 4(10) -> 6(2)
# 4 -> 3(9) -> 5(10)
# 6 -> 5(2) -> 7(1) -> 8(6)
# Distance from node: 0
# Node 0 has distance: 0
# Node 1 has distance: 4
# Node 2 has distance: 12
# Node 3 has distance: 19
# Node 4 has distance: 21
# Node 5 has distance: 11
# Node 6 has distance: 9
# Node 7 has distance: 8
# Node 8 has distance: 14
# ----Path to reach 4 from 0----
# 0 -> 7 -> 6 -> 5 -> 4
# Total cost of path:  21






"""simple docstring"""




import hashlib
import importlib.util
import json
import os
import pathlib
from types import ModuleType

import pytest
import requests

lowerCamelCase_	:		int         =   pathlib.Path.cwd().joinpath('project_euler')
lowerCamelCase_	:		str         =   pathlib.Path.cwd().joinpath(
    'scripts', 'project_euler_answers.json'
)

with open(PROJECT_EULER_ANSWERS_PATH) as file_handle:
   lowerCamelCase_	:		dict[str, str]         =   json.load(file_handle)





def 		UpperCAmelCase__						(	_UpperCAmelCase   ):






  """simple docstring"""





  A_    :			List[str]									=    importlib.util.spec_from_file_location(file_path.name					,   str(_UpperCAmelCase   )   )
  A_    :			int									=    importlib.util.module_from_spec(_UpperCAmelCase   )  # type: ignore
  spec.loader.exec_module(_UpperCAmelCase   )  # type: ignore
  return module





def 		UpperCAmelCase__						(	):






  """simple docstring"""





  A_    :			Tuple									=    []
  for problem_dir_path in PROJECT_EULER_DIR_PATH.iterdir():
    if problem_dir_path.is_file() or problem_dir_path.name.startswith('_'   ):
      continue
    for file_path in problem_dir_path.iterdir():
      if file_path.suffix != ".py" or file_path.name.startswith(('_', 'test')   ):
        continue
      solution_file_paths.append(_UpperCAmelCase   )
  return solution_file_paths





def 		UpperCAmelCase__						(	):






  """simple docstring"""





  with open(os.environ['GITHUB_EVENT_PATH']   ) as file:
    A_    :			str									=    json.load(_UpperCAmelCase   )
  return event["pull_request"]["url"] + "/files"





def 		UpperCAmelCase__						(	):






  """simple docstring"""





  A_    :			Any									=    []
  A_    :			Optional[Any]									=    {
      'Accept': 'application/vnd.github.v3+json',
      'Authorization': 'token ' + os.environ['GITHUB_TOKEN'],
  }
  A_    :			Union[str, Any]									=    requests.get(get_files_url()					,   headers=_UpperCAmelCase   ).json()
  for file in files:
    A_    :			Optional[int]									=    pathlib.Path.cwd().joinpath(file['filename']   )
    if (
        filepath.suffix != ".py"
        or filepath.name.startswith(('_', 'test')   )
        or not filepath.name.startswith('sol'   )
    ):
      continue
    solution_file_paths.append(_UpperCAmelCase   )
  return solution_file_paths





def 		UpperCAmelCase__						(	):






  """simple docstring"""





  if os.environ.get('CI'   ) and os.environ.get('GITHUB_EVENT_NAME'   ) == "pull_request":
    # Return only if there are any, otherwise default to all solutions
    if filepaths := added_solution_file_path():
      return filepaths
  return all_solution_file_paths()





@pytest.mark.parametrize(
    'solution_path'					,   collect_solution_file_paths()					,   ids=lambda _UpperCAmelCase   : f"""{path.parent.name}/{path.name}"""					,   )
def 		UpperCAmelCase__						(	_UpperCAmelCase   ):






  """simple docstring"""





  A_    :			str									=    solution_path.parent.name[8:].zfill(3   )
  A_    :			str									=    PROBLEM_ANSWERS[problem_number]
  A_    :			List[Any]									=    convert_path_to_module(_UpperCAmelCase   )
  A_    :			Optional[int]									=    str(solution_module.solution()   )  # type: ignore
  A_    :			Any									=    hashlib.shaaaa(answer.encode()   ).hexdigest()
  assert (
      answer == expected
  ), f"""Expected solution to {problem_number} to have hash {expected}, got {answer}"""