'''simple docstring'''




import timeit





class        __magic_name__		:







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







			def __mul__(      self							:    int							,     lowercase_							:    int       ):
										lowercase_   :     str									=			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 				lowerCamelCase      ( UpperCAmelCase__			:   Union[str, Any] , UpperCAmelCase__			:   Dict					)     -> Union[str, Any]:
							lowercase_   :     List[Any]									=			Matrix([[1, 0], [0, 1]]					)
							while b > 0:
														if b & 1:
																					matrix *= a
														a *= a
														b >>= 1
							return matrix




def 				lowerCamelCase      ( UpperCAmelCase__			:   Union[str, Any] , UpperCAmelCase__			:   List[Any] , UpperCAmelCase__			:   str					)     -> Any:
							# Trivial Cases
							if n == 1:
														return fa
							elif n == 2:
														return fa
							lowercase_   :     Dict									=			Matrix([[1, 1], [1, 0]]					)
							lowercase_   :     Dict									=			modular_exponentiation(UpperCAmelCase__ , n - 2					)
							return fa * matrix.t[0][0] + fa * matrix.t[0][1]




def 				lowerCamelCase      ( UpperCAmelCase__			:   List[str] , UpperCAmelCase__			:   Any , UpperCAmelCase__			:   int					)     -> List[Any]:
							# Trivial Cases
							if n == 1:
														return fa
							elif n == 2:
														return fa

							lowercase_   :     str									=			fa
							lowercase_   :     List[Any]									=			fa
							n -= 2

							while n > 0:
														lowercase_		,		lowercase_   :     str									=			fn_a + fn_a, fn_a
														n -= 1

							return fn_a




def 				lowerCamelCase      ( )     -> List[Any]:
							lowercase_   :     int									=			"""
from random import randint
from __main__ import fibonacci_with_matrix_exponentiation
"""
							lowercase_   :     int									=			"""fibonacci_with_matrix_exponentiation(randint(1,70000), 1, 1)"""
							lowercase_   :     int									=			timeit.timeit(setup=UpperCAmelCase__ , stmt=UpperCAmelCase__ , number=100					)
							print("""With matrix exponentiation the average execution time is """ , exec_time / 100					)
							return exec_time




def 				lowerCamelCase      ( )     -> List[str]:
							lowercase_   :     Optional[int]									=			"""
from random import randint
from __main__ import simple_fibonacci
"""
							lowercase_   :     List[Any]									=			"""simple_fibonacci(randint(1,70000), 1, 1)"""
							lowercase_   :     Optional[int]									=			timeit.timeit(setup=UpperCAmelCase__ , stmt=UpperCAmelCase__ , number=100					)
							print(
							    """Without matrix exponentiation the average execution time is """ , exec_time / 100					)
							return exec_time




def 				lowerCamelCase      ( )     -> Tuple:
							matrix_exponentiation_time()
							simple_fibonacci_time()


if __name__ == "__main__":
						main()






'''simple docstring'''




from __future__ import annotations





class        __magic_name__		:







			def __init__(      self							:    List[str]							,     lowercase_							:    int       ):
										lowercase_   :     List[str]									=			vertices
										lowercase_   :     Optional[Any]									=			[[0] * vertices for _ in range(lowercase_       )]







			def       SCREAMING_SNAKE_CASE_	(      self							:    int							,     lowercase_							:    list[int]       ):
										print("""Vertex \t Distance from Source"""       )
										for vertex in range(self.vertices       ):
																	print(lowercase_							,     """\t\t"""							,     distances_from_source[vertex]       )







			def       SCREAMING_SNAKE_CASE_	(      self							:    str							,     lowercase_							:    list[int]							,     lowercase_							:    list[bool]       ):
										lowercase_   :     Dict									=			1E7
										lowercase_   :     int									=			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:
																								lowercase_   :     Tuple									=			distances_from_source[vertex]
																								lowercase_   :     str									=			vertex
										return min_index







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

										for _ in range(self.vertices       ):
																	lowercase_   :     Tuple									=			self.minimum_distance(lowercase_							,     lowercase_       )
																	lowercase_   :     Union[str, Any]									=			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]
																								):
																															lowercase_   :     Any									=			distances[u] + self.graph[u][v]

										self.print_solution(lowercase_       )


if __name__ == "__main__":
						_lowercase		:					Any													=		Graph(9)
						_lowercase		:					Any													=		[
						    [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)





