





'''simple docstring'''







from __future__ import annotations

from collections import deque
from collections.abc import Iterator
from dataclasses import dataclass
@dataclass
class 			_lowercase						:
     _UpperCAmelCase										=					42
     _UpperCAmelCase										=					42




class 			_lowercase						:







     def __init__( self    ,   A__    ) ->	Union[str, Any]:
      snake_case				=			[[] for _ in range(A__    )]
      snake_case				=			size







     def __getitem__( self    ,   A__    ) ->	Iterator[Edge]:
      return iter(self._graph[vertex]    )







     @property
     def     UpperCamelCase			( self    ) ->	Union[str, Any]:
      return self._size







     def     UpperCamelCase			( self    ,   A__    ,   A__    ,   A__    ) ->	str:
      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(A__    ,   A__    )    )







     def     UpperCamelCase			( self    ,   A__    ,   A__    ) ->	int | None:
      snake_case				=			deque([start_vertex]    )
      snake_case				=			[None] * self.size
      snake_case				=			0

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

       for edge in self[current_vertex]:
        snake_case				=			current_distance + edge.weight
        snake_case				=			distances[edge.destination_vertex]
        if (
            isinstance(A__    ,   A__    )
            and new_distance >= dest_vertex_distance
        ):
         continue
        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()








'''simple docstring'''







from __future__ import annotations

from collections.abc import Iterator
class 			_lowercase						:







     def __init__( self    ,   A__    ) ->	None:
      snake_case				=			value
      snake_case				=			None
      snake_case				=			None




class 			_lowercase						:







     def __init__( self    ,   A__    ) ->	None:
      snake_case				=			tree







     def     UpperCamelCase			( self    ,   A__    ) ->	int:
      if node is None:
       return 0
      return node.value + (
          self.depth_first_search(node.left    ) + self.depth_first_search(node.right    )
      )







     def __iter__( self    ) ->	Iterator[int]:
      yield self.depth_first_search(self.tree    )


if __name__ == "__main__":
   import doctest

   doctest.testmod()

