





from __future__ import annotations

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

@dataclass
class      A       :
      _snake_case							     =42
      _snake_case							     =42

class      A       :



      def __init__(	self:						Tuple		,  _lowerCAmelCase:						int       )						->    Optional[int]:
         '''simple docstring'''

         UpperCAmelCase_											=[[] for _ in range(_lowerCAmelCase       )]
         UpperCAmelCase_											=size



      def __getitem__(	self:						int		,  _lowerCAmelCase:						int       )						->    Iterator[Edge]:
         '''simple docstring'''

         return iter(self._graph[vertex]       )



      @property
      def 	lowerCAmelCase__    (	self:						int       )						->    Union[str, Any]:
         '''simple docstring'''

         return self._size



      def 	lowerCAmelCase__    (	self:						Tuple		,  _lowerCAmelCase:						int		,  _lowerCAmelCase:						int		,  _lowerCAmelCase:						int       )						->    Union[str, Any]:
         '''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 	lowerCAmelCase__    (	self:						Tuple		,  _lowerCAmelCase:						int		,  _lowerCAmelCase:						int       )						->    int | None:
         '''simple docstring'''

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

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

            for edge in self[current_vertex]:
               UpperCAmelCase_											=current_distance + edge.weight
               UpperCAmelCase_											=distances[edge.destination_vertex]
               if (
                   isinstance(_lowerCAmelCase		,  _lowerCAmelCase       )
                   and new_distance >= dest_vertex_distance
               ):
                  continue
               UpperCAmelCase_											=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 math_equivalence  # From: git+https://github.com/hendrycks/math.git

import datasets


__lowercase  :   int						      ="""\
@article{hendrycksmath2021,
  title={Measuring Mathematical Problem Solving With the MATH Dataset},
  author={Dan Hendrycks
    and Collin Burns
    and Saurav Kadavath
    and Akul Arora
    and Steven Basart
    and Eric Tang
    and Dawn Song
    and Jacob Steinhardt},
  journal={arXiv preprint arXiv:2103.03874},
  year={2021}
}
"""


__lowercase  :   List[Any]						      ="""\
This metric is used to assess performance on the Mathematics Aptitude Test of Heuristics (MATH) dataset.
It first canonicalizes the inputs (e.g., converting \"1/2\" to \"\\frac{1}{2}\") and then computes accuracy.
"""


__lowercase  :   str						      =R"""
Calculates accuracy after canonicalizing inputs.

Args:
    predictions: list of predictions to score. Each prediction
        is a string that contains natural language and LaTex.
    references: list of reference for each prediction. Each
        reference is a string that contains natural language
        and LaTex.
Returns:
    accuracy: accuracy after canonicalizing inputs
        (e.g., converting \"1/2\" to \"\\frac{1}{2}\")

Examples:
    >>> metric = datasets.load_metric(\"competition_math\")
    >>> results = metric.compute(references=[\"\\frac{1}{2}\"], predictions=[\"1/2\"])
    >>> print(results)
    {'accuracy': 1.0}
"""

@datasets.utils.file_utils.add_end_docstrings(_DESCRIPTION		,      _KWARGS_DESCRIPTION						)
class      A       (	datasets.Metric						):



      def 	lowerCAmelCase__    (	self:						Any       )						->    Optional[Any]:
         '''simple docstring'''

         return datasets.MetricInfo(
             description=_DESCRIPTION		,  citation=_CITATION		,  inputs_description=_KWARGS_DESCRIPTION		,  features=datasets.Features(
                 {
                     "predictions": datasets.Value("string"       ),
                     "references": datasets.Value("string"       ),
                 }       )		,  homepage="https://github.com/hendrycks/math"		,  codebase_urls=["https://github.com/hendrycks/math"]		,  )






      def 	lowerCAmelCase__    (	self:						Any		,  _lowerCAmelCase:						Tuple		,  _lowerCAmelCase:						Union[str, Any]       )						->    Dict:
         '''simple docstring'''

         UpperCAmelCase_											=0.0
         for i, j in zip(_lowerCAmelCase		,  _lowerCAmelCase       ):
            n_correct += 1.0 if math_equivalence.is_equiv(_lowerCAmelCase		,  _lowerCAmelCase       ) else 0.0
         UpperCAmelCase_											=n_correct / len(_lowerCAmelCase       )
         return {
             "accuracy": accuracy,
         }




