'''simple docstring'''





from __future__ import annotations

from collections import deque
from collections.abc import Iterator
from dataclasses import dataclass







@dataclass
class __snake_case       :
   lowerCAmelCase_														=							42
   lowerCAmelCase_														=							42







class __snake_case       :




   def __init__(					self    :       List[str] ,			_lowercase    :       int   ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__    							=   [[] for _ in range(lowerCAmelCase__   )]
     SCREAMING_SNAKE_CASE__    							=   size




   def __getitem__(					self    :       str ,			_lowercase    :       int   ):



     """simple docstring"""






     return iter(self._graph[vertex]   )




   @property
   def 			__a		(					self    :       Union[str, Any]   ):



     """simple docstring"""






     return self._size




   def 			__a		(					self    :       Optional[Any] ,			_lowercase    :       int ,			_lowercase    :       int ,			_lowercase    :       int   ):



     """simple docstring"""






     if weight not in (0, 1):
       raise ValueError("""Edge weight must be either 0 or 1."""   )

     if to_vertex < 0 or to_vertex >= self.size:
       raise ValueError("""Vertex indexes must be in [0; size)."""   )

     self._graph[from_vertex].append(Edge(lowerCAmelCase__ ,			lowerCAmelCase__   )   )




   def 			__a		(					self    :       str ,			_lowercase    :       int ,			_lowercase    :       int   ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__    							=   deque([start_vertex]   )
     SCREAMING_SNAKE_CASE__    							=   [None] * self.size
     SCREAMING_SNAKE_CASE__    							=   0

     while queue:
       SCREAMING_SNAKE_CASE__    							=   queue.popleft()
       SCREAMING_SNAKE_CASE__    							=   distances[current_vertex]
       if current_distance is None:
         continue

       for edge in self[current_vertex]:
         SCREAMING_SNAKE_CASE__    							=   current_distance + edge.weight
         SCREAMING_SNAKE_CASE__    							=   distances[edge.destination_vertex]
         if (
             isinstance(lowerCAmelCase__ ,			lowerCAmelCase__   )
             and new_distance >= dest_vertex_distance
         ):
           continue
         SCREAMING_SNAKE_CASE__    							=   new_distance
         if edge.weight == 0:
           queue.appendleft(edge.destination_vertex   )
         else:
           queue.append(edge.destination_vertex   )

     if distances[finish_vertex] is None:
       raise ValueError("""No path from start_vertex to finish_vertex."""   )

     return distances[finish_vertex]


if __name__ == "__main__":
   import doctest

   doctest.testmod()

import pickle
import unittest

import torch

from accelerate import Accelerator
from accelerate.state import AcceleratorState
from accelerate.test_utils import require_cpu







@require_cpu
class __snake_case       (		unittest.TestCase	):




   def 			__a		(					self    :       Any   ):



     """simple docstring"""






     SCREAMING_SNAKE_CASE__    							=   torch.nn.Linear(10 ,			10   )
     SCREAMING_SNAKE_CASE__    							=   torch.optim.SGD(model.parameters() ,			0.1   )
     SCREAMING_SNAKE_CASE__    							=   Accelerator()
     SCREAMING_SNAKE_CASE__    							=   accelerator.prepare(_lowercase   )
     try:
       pickle.loads(pickle.dumps(_lowercase   )   )
     except Exception as e:
       self.fail(f"""Accelerated optimizer pickling failed with {e}"""   )
     AcceleratorState._reset_state()
