
import sys
from collections import defaultdict



class 		UpperCamelCase__  :
   def __init__(self			: Optional[Any]       ):
    __a			:  str		    =  []
   def 				lowerCAmelCase      (self			: int ,    snake_case_			: List[Any]       ):
    return self.node_position[vertex]
   def 				lowerCAmelCase      (self			: List[str] ,    snake_case_			: str ,    snake_case_			: List[str]       ):
    __a			:  Any		    =  pos
   def 				lowerCAmelCase      (self			: str ,    snake_case_			: Any ,    snake_case_			: Optional[Any] ,    snake_case_			: Dict ,    snake_case_			: List[str]       ):
    if start > size // 2 - 1:
     return
    else:
     if 2 * start + 2 >= size:
      __a			:  str		    =  2 * start + 1
     else:
      if heap[2 * start + 1] < heap[2 * start + 2]:
       __a			:  Union[str, Any]		    =  2 * start + 1
      else:
       __a			:  Dict		    =  2 * start + 2
     if heap[smallest_child] < heap[start]:
      __a    ,	__a			:  List[Any]		    =  heap[smallest_child], positions[smallest_child]
      __a    ,	__a			:  List[str]		    =  (
          heap[start],
          positions[start],
      )
      __a    ,	__a			:  Any		    =  temp, tempa

      __a			:  Dict		    =  self.get_position(positions[smallest_child]       )
      self.set_position(
          positions[smallest_child] ,    self.get_position(positions[start]       )       )
      self.set_position(positions[start] ,    snake_case_       )

      self.top_to_bottom(snake_case_ ,    snake_case_ ,    snake_case_ ,    snake_case_       )
   def 				lowerCAmelCase      (self			: Optional[Any] ,    snake_case_			: str ,    snake_case_			: Optional[int] ,    snake_case_			: int ,    snake_case_			: int       ):
    __a			:  Any		    =  position[index]

    while index != 0:
     __a			:  int		    =  int((index - 2) / 2       ) if index % 2 == 0 else int((index - 1) / 2       )

     if val < heap[parent]:
      __a			:  List[Any]		    =  heap[parent]
      __a			:  Dict		    =  position[parent]
      self.set_position(position[parent] ,    snake_case_       )
     else:
      __a			:  Dict		    =  val
      __a			:  Tuple		    =  temp
      self.set_position(snake_case_ ,    snake_case_       )
      break
     __a			:  Tuple		    =  parent
    else:
     __a			:  Optional[Any]		    =  val
     __a			:  List[str]		    =  temp
     self.set_position(snake_case_ ,    0       )
   def 				lowerCAmelCase      (self			: int ,    snake_case_			: Union[str, Any] ,    snake_case_			: Optional[int]       ):
    __a			:  List[str]		    =  len(snake_case_       ) // 2 - 1
    for i in range(snake_case_ ,    -1 ,    -1       ):
     self.top_to_bottom(snake_case_ ,    snake_case_ ,    len(snake_case_       ) ,    snake_case_       )







   def 				lowerCAmelCase      (self			: Tuple ,    snake_case_			: int ,    snake_case_			: List[str]       ):
    __a			:  Optional[Any]		    =  positions[0]
    __a			:  Dict		    =  sys.maxsize
    self.top_to_bottom(snake_case_ ,    0 ,    len(snake_case_       ) ,    snake_case_       )
    return temp





def        __UpperCamelCase					(    lowerCAmelCase__							:    Optional[int]  ):
 __a			:  Tuple		    =  Heap()

 __a			:  Optional[int]		    =  [0] * len(lowerCAmelCase__  )
 __a			:  Optional[Any]		    =  [-1] * len(lowerCAmelCase__  )  # Neighboring Tree Vertex of selected vertex
 # Minimum Distance of explored vertex with neighboring vertex of partial tree
 # formed in graph
 __a			:  Any		    =  []  # Heap of Distance of vertices from their neighboring vertex
 __a			:  Optional[int]		    =  []

 for vertex in range(len(lowerCAmelCase__  )  ):
  distance_tv.append(sys.maxsize  )
  positions.append(lowerCAmelCase__  )
  heap.node_position.append(lowerCAmelCase__  )

 __a			:  List[str]		    =  []
 __a			:  Tuple		    =  1
 __a			:  Tuple		    =  sys.maxsize
 for neighbor, distance in adjacency_list[0]:
  __a			:  Dict		    =  0
  __a			:  Optional[int]		    =  distance
 heap.heapify(lowerCAmelCase__  ,       lowerCAmelCase__  )

 for _ in range(1  ,       len(lowerCAmelCase__  )  ):
  __a			:  List[str]		    =  heap.delete_minimum(lowerCAmelCase__  ,       lowerCAmelCase__  )
  if visited[vertex] == 0:
   tree_edges.append((nbr_tv[vertex], vertex)  )
   __a			:  Union[str, Any]		    =  1
   for neighbor, distance in adjacency_list[vertex]:
    if (
        visited[neighbor] == 0
        and distance < distance_tv[heap.get_position(lowerCAmelCase__  )]
    ):
     __a			:  Union[str, Any]		    =  distance
     heap.bottom_to_top(
         lowerCAmelCase__  ,       heap.get_position(lowerCAmelCase__  )  ,       lowerCAmelCase__  ,       lowerCAmelCase__  )
     __a			:  List[str]		    =  vertex
 return tree_edges


if __name__ == "__main__":  # pragma: no cover
      # < --------- Prims Algorithm --------- >
      lowercase__          =int(input('Enter number of edges: ').strip())
      lowercase__          =defaultdict(list)
      for _ in range(edges_number):
            lowercase__          =[int(x) for x in input().strip().split()]
            adjacency_list[edge[0]].append([edge[1], edge[2]])
            adjacency_list[edge[1]].append([edge[0], edge[2]])
      print(prisms_algorithm(adjacency_list))


import json
import os
import tempfile

import datasets
from utils import generate_example_dataset, get_duration


lowercase__          =50000
lowercase__          =5000

lowercase__       ,      lowercase__          =os.path.split(__file__)
lowercase__          =os.path.join(RESULTS_BASEPATH, 'results', RESULTS_FILENAME.replace('.py', '.json'))




@get_duration
def        __UpperCamelCase					(    lowerCAmelCase__							:    datasets.Dataset  ,       lowerCAmelCase__							:    List[str]  ):
 for i in range(lowerCAmelCase__  ):
  __a			:  str		    =  dataset[i]




@get_duration
def        __UpperCamelCase					(    lowerCAmelCase__							:    datasets.Dataset  ,       lowerCAmelCase__							:    Optional[Any]  ,       lowerCAmelCase__							:    Tuple  ):
 for i in range(0  ,       len(lowerCAmelCase__  )  ,       lowerCAmelCase__  ):
  __a			:  Optional[int]		    =  dataset[i : i + batch_size]




@get_duration
def        __UpperCamelCase					(    lowerCAmelCase__							:    datasets.Dataset  ,       lowerCAmelCase__							:    Union[str, Any]  ,       lowerCAmelCase__							:    str  ):
 with dataset.formatted_as(type=lowerCAmelCase__  ):
  for i in range(lowerCAmelCase__  ):
   __a			:  Dict		    =  dataset[i]




@get_duration
def        __UpperCamelCase					(    lowerCAmelCase__							:    datasets.Dataset  ,       lowerCAmelCase__							:    List[str]  ,       lowerCAmelCase__							:    Optional[Any]  ,       lowerCAmelCase__							:    int  ):
 with dataset.formatted_as(type=lowerCAmelCase__  ):
  for i in range(0  ,       lowerCAmelCase__  ,       lowerCAmelCase__  ):
   __a			:  int		    =  dataset[i : i + batch_size]




def        __UpperCamelCase					(    ):
 __a			:  Any		    =  {'''num examples''': SPEED_TEST_N_EXAMPLES}
 __a			:  List[Any]		    =  [
     (read, {'''length''': SMALL_TEST}),
     (read, {'''length''': SPEED_TEST_N_EXAMPLES}),
     (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 1_0}),
     (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 1_0_0}),
     (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 1_0_0_0}),
     (read_formatted, {'''type''': '''numpy''', '''length''': SMALL_TEST}),
     (read_formatted, {'''type''': '''pandas''', '''length''': SMALL_TEST}),
     (read_formatted, {'''type''': '''torch''', '''length''': SMALL_TEST}),
     (read_formatted, {'''type''': '''tensorflow''', '''length''': SMALL_TEST}),
     (read_formatted_batch, {'''type''': '''numpy''', '''length''': SMALL_TEST, '''batch_size''': 1_0}),
     (read_formatted_batch, {'''type''': '''numpy''', '''length''': SMALL_TEST, '''batch_size''': 1_0_0_0}),
 ]

 __a			:  Union[str, Any]		    =  [
     (read, {'''length''': SMALL_TEST}),
     (read, {'''length''': SPEED_TEST_N_EXAMPLES}),
     (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 1_0}),
     (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 1_0_0}),
     (read_batch, {'''length''': SPEED_TEST_N_EXAMPLES, '''batch_size''': 1_0_0_0}),
     (read_formatted, {'''type''': '''numpy''', '''length''': SMALL_TEST}),
     (read_formatted_batch, {'''type''': '''numpy''', '''length''': SMALL_TEST, '''batch_size''': 1_0}),
     (read_formatted_batch, {'''type''': '''numpy''', '''length''': SMALL_TEST, '''batch_size''': 1_0_0_0}),
 ]
 with tempfile.TemporaryDirectory() as tmp_dir:
  print('''generating dataset'''  )
  __a			:  Optional[Any]		    =  datasets.Features(
      {'''list''': datasets.Sequence(datasets.Value('''float32'''  )  ), '''numbers''': datasets.Value('''float32'''  )}  )
  __a			:  Optional[int]		    =  generate_example_dataset(
      os.path.join(lowerCAmelCase__  ,       '''dataset.arrow'''  )  ,       lowerCAmelCase__  ,       num_examples=lowerCAmelCase__  ,       seq_shapes={'''list''': (1_0_0,)}  ,       )
  print('''first set of iterations'''  )
  for func, kwargs in functions:
   print(func.__name__  ,       str(lowerCAmelCase__  )  )
   __a			:  str		    =  func(lowerCAmelCase__  ,       **lowerCAmelCase__  )

  print('''shuffling dataset'''  )
  __a			:  int		    =  dataset.shuffle()
  print('''Second set of iterations (after shuffling'''  )
  for func, kwargs in functions_shuffled:
   print('''shuffled '''  ,       func.__name__  ,       str(lowerCAmelCase__  )  )
   __a			:  List[Any]		    =  func(
       lowerCAmelCase__  ,       **lowerCAmelCase__  )

 with open(lowerCAmelCase__  ,       '''wb'''  ) as f:
  f.write(json.dumps(lowerCAmelCase__  ).encode('''utf-8'''  )  )


if __name__ == "__main__":  # useful to run the profiler
      benchmark_iterating()
