
'''simple docstring'''

import timeit







class 	__lowerCAmelCase    :



     def __init__(self						,	lowerCAmelCase__	):
          if isinstance(lowerCAmelCase__						,	lowerCAmelCase__	):  # Initializes a matrix identical to the one provided.
               _UpperCAmelCase					:  List[str]         =    arg
               _UpperCAmelCase					:  Optional[int]         =    len(lowerCAmelCase__	)
          else:  # Initializes a square matrix of the given size and set values to zero.
               _UpperCAmelCase					:  int         =    arg
               _UpperCAmelCase					:  Union[str, Any]         =    [[0 for _ in range(self.n	)] for _ in range(self.n	)]



     def __mul__(self						,	lowerCAmelCase__	):
          _UpperCAmelCase					:  Dict         =    Matrix(self.n	)
          for i in range(self.n	):
               for j in range(self.n	):
                    for k in range(self.n	):
                         matrix.t[i][j] += self.t[i][k] * b.t[k][j]
          return matrix







def __A  (    lowerCAmelCase_ ,       lowerCAmelCase_       ):
     _UpperCAmelCase					:  int         =    Matrix([[1, 0], [0, 1]]       )
     while b > 0:
          if b & 1:
               matrix *= a
          a *= a
          b >>= 1
     return matrix







def __A  (    lowerCAmelCase_ ,       lowerCAmelCase_ ,       lowerCAmelCase_       ):
     # Trivial Cases
     if n == 1:
          return fa
     elif n == 2:
          return fa
     _UpperCAmelCase					:  str         =    Matrix([[1, 1], [1, 0]]       )
     _UpperCAmelCase					:  Optional[int]         =    modular_exponentiation(lowerCAmelCase_ ,       n - 2       )
     return fa * matrix.t[0][0] + fa * matrix.t[0][1]







def __A  (    lowerCAmelCase_ ,       lowerCAmelCase_ ,       lowerCAmelCase_       ):
     # Trivial Cases
     if n == 1:
          return fa
     elif n == 2:
          return fa

     _UpperCAmelCase					:  Optional[int]         =    fa
     _UpperCAmelCase					:  Dict         =    fa
     n -= 2

     while n > 0:
          _UpperCAmelCase  ,     _UpperCAmelCase					:  Any         =    fn_a + fn_a, fn_a
          n -= 1

     return fn_a







def __A  (    ):
     _UpperCAmelCase					:  Union[str, Any]         =    """
from random import randint
from __main__ import fibonacci_with_matrix_exponentiation
"""
     _UpperCAmelCase					:  Union[str, Any]         =    """fibonacci_with_matrix_exponentiation(randint(1,70000), 1, 1)"""
     _UpperCAmelCase					:  List[str]         =    timeit.timeit(setup=lowerCAmelCase_ ,       stmt=lowerCAmelCase_ ,       number=100       )
     print("""With matrix exponentiation the average execution time is """ ,       exec_time / 100       )
     return exec_time







def __A  (    ):
     _UpperCAmelCase					:  Dict         =    """
from random import randint
from __main__ import simple_fibonacci
"""
     _UpperCAmelCase					:  Optional[int]         =    """simple_fibonacci(randint(1,70000), 1, 1)"""
     _UpperCAmelCase					:  Any         =    timeit.timeit(setup=lowerCAmelCase_ ,       stmt=lowerCAmelCase_ ,       number=100       )
     print(
         """Without matrix exponentiation the average execution time is """ ,       exec_time / 100       )
     return exec_time







def __A  (    ):
     matrix_exponentiation_time()
     simple_fibonacci_time()


if __name__ == "__main__":
   main()





from __future__ import annotations

class  a     :


						def __init__(				self  ,    A_		):







										'''simple docstring'''


										_UpperCAmelCase				:						List[Any]       						=			vertices
										_UpperCAmelCase				:						List[str]       						=			[[0] * vertices for _ in range(A_		)]


						def 				_UpperCAmelCase (				self  ,    A_		):







										'''simple docstring'''


										print("Vertex \t Distance from Source"		)
										for vertex in range(self.vertices		):
														print(A_  ,    "\t\t"  ,    distances_from_source[vertex]		)


						def 				_UpperCAmelCase (				self  ,    A_  ,    A_		):







										'''simple docstring'''


										_UpperCAmelCase				:						Tuple       						=			1e7
										_UpperCAmelCase				:						Any       						=			0

										# Search not nearest vertex not in the shortest path tree
										for vertex in range(self.vertices		):
														if distances_from_source[vertex] < minimum and visited[vertex] is False:
																		_UpperCAmelCase				:						List[Any]       						=			distances_from_source[vertex]
																		_UpperCAmelCase				:						Tuple       						=			vertex
										return min_index





						def 				_UpperCAmelCase (				self  ,    A_		):







										'''simple docstring'''


										_UpperCAmelCase				:						Union[str, Any]       						=			[int(1e7		)] * self.vertices  # distances from the source
										_UpperCAmelCase				:						Optional[Any]       						=			0
										_UpperCAmelCase				:						List[str]       						=			[False] * self.vertices

										for _ in range(self.vertices		):
														_UpperCAmelCase				:						str       						=			self.minimum_distance(A_  ,    A_		)
														_UpperCAmelCase				:						str       						=			True

														# Update dist value of the adjacent vertices
														# of the picked vertex only if the current
														# distance is greater than new distance and
														# the vertex in not in the shortest path tree
														for v in range(self.vertices		):
																		if (
																		    self.graph[u][v] > 0
																		    and visited[v] is False
																		    and distances[v] > distances[u] + self.graph[u][v]
																		):
																						_UpperCAmelCase				:						str       						=			distances[u] + self.graph[u][v]

										self.print_solution(A_		)


if __name__ == "__main__":
					SCREAMING_SNAKE_CASE_						=					Graph(9)
					SCREAMING_SNAKE_CASE_						=					[
					    [0, 4, 0, 0, 0, 0, 0, 8, 0],
					    [4, 0, 8, 0, 0, 0, 0, 11, 0],
					    [0, 8, 0, 7, 0, 4, 0, 0, 2],
					    [0, 0, 7, 0, 9, 14, 0, 0, 0],
					    [0, 0, 0, 9, 0, 10, 0, 0, 0],
					    [0, 0, 4, 14, 10, 0, 2, 0, 0],
					    [0, 0, 0, 0, 0, 2, 0, 1, 6],
					    [8, 11, 0, 0, 0, 0, 1, 0, 7],
					    [0, 0, 2, 0, 0, 0, 6, 7, 0],
					]
					graph.dijkstra(0)


