

from collections import deque
from math import floor
from random import random
from time import time

class 							UpperCAmelCase_						:
							"""simple docstring"""







							def __init__(     self			)       ->       List[str]:
												_a      :       Any   =						{}


							def 							__lowercase							(     self			,				_a			,				_a			,				_a=1			)       ->       Tuple:
												if self.graph.get(_a			):
																	if self.graph[u].count([w, v]			) == 0:
																						self.graph[u].append([w, v]			)
												else:
																	_a      :       Union[str, Any]   =						[[w, v]]
												if not self.graph.get(_a			):
																	_a      :       Dict   =						[]


							def 							__lowercase							(     self			)       ->       Union[str, Any]:
												return list(self.graph			)


							def 							__lowercase							(     self			,				_a			,				_a			)       ->       Optional[Any]:
												if self.graph.get(_a			):
																	for _ in self.graph[u]:
																						if _[1] == v:
																											self.graph[u].remove(_a			)


							def 							__lowercase							(     self			,				_a=-2			,				_a=-1			)       ->       Dict:
												if s == d:
																	return []
												_a      :       Optional[int]   =						[]
												_a      :       int   =						[]
												if s == -2:
																	_a      :       Optional[int]   =						list(self.graph			)[0]
												stack.append(_a			)
												visited.append(_a			)
												_a      :       Union[str, Any]   =						s

												while True:
																	# check if there is any non isolated nodes
																	if len(self.graph[s]			) != 0:
																						_a      :       Union[str, Any]   =						s
																						for node in self.graph[s]:
																											if visited.count(node[1]			) < 1:
																																if node[1] == d:
																																					visited.append(_a			)
																																					return visited
																																else:
																																					stack.append(node[1]			)
																																					visited.append(node[1]			)
																																					_a      :       List[str]   =						node[1]
																																					break

            # check if all the children are visited
																	if s == ss:
																						stack.pop()
																						if len(_a			) != 0:
																											_a      :       Any   =						stack[len(_a			) - 1]
																	else:
																						_a      :       Dict   =						ss

																	# check if se have reached the starting point
																	if len(_a			) == 0:
																						return visited


							def 							__lowercase							(     self			,				_a=-1			)       ->       List[str]:
												if c == -1:
																	_a      :       List[str]   =						floor(random() * 1_0_0_0_0			) + 1_0
												for i in range(_a			):
																	# every vertex has max 100 edges
																	for _ in range(floor(random() * 1_0_2			) + 1			):
																						_a      :       Optional[Any]   =						floor(random() * c			) + 1
																						if n != i:
																											self.add_pair(_a			,				_a			,				1			)


							def 							__lowercase							(     self			,				_a=-2			)       ->       List[Any]:
												_a      :       Any   =						deque()
												_a      :       List[str]   =						[]
												if s == -2:
																	_a      :       Any   =						list(self.graph			)[0]
												d.append(_a			)
												visited.append(_a			)
												while d:
																	_a      :       Optional[Any]   =						d.popleft()
																	if len(self.graph[s]			) != 0:
																						for node in self.graph[s]:
																											if visited.count(node[1]			) < 1:
																																d.append(node[1]			)
																																visited.append(node[1]			)
												return visited


							def 							__lowercase							(     self			,				_a			)       ->       Optional[Any]:
												_a      :       Optional[int]   =						0
												for x in self.graph:
																	for y in self.graph[x]:
																						if y[1] == u:
																											count += 1
												return count


							def 							__lowercase							(     self			,				_a			)       ->       int:
												return len(self.graph[u]			)


							def 							__lowercase							(     self			,				_a=-2			)       ->       int:
												_a      :       str   =						[]
												_a      :       str   =						[]
												if s == -2:
																	_a      :       Any   =						list(self.graph			)[0]
												stack.append(_a			)
												visited.append(_a			)
												_a      :       Dict   =						s
												_a      :       Union[str, Any]   =						[]

												while True:
																	# check if there is any non isolated nodes
																	if len(self.graph[s]			) != 0:
																						_a      :       int   =						s
																						for node in self.graph[s]:
																											if visited.count(node[1]			) < 1:
																																stack.append(node[1]			)
																																visited.append(node[1]			)
																																_a      :       Optional[int]   =						node[1]
																																break

            # check if all the children are visited
																	if s == ss:
																						sorted_nodes.append(stack.pop()			)
																						if len(_a			) != 0:
																											_a      :       List[Any]   =						stack[len(_a			) - 1]
																	else:
																						_a      :       Dict   =						ss

																	# check if se have reached the starting point
																	if len(_a			) == 0:
																						return sorted_nodes


							def 							__lowercase							(     self			)       ->       Any:
												_a      :       List[str]   =						[]
												_a      :       Optional[Any]   =						[]
												_a      :       Optional[Any]   =						list(self.graph			)[0]
												stack.append(_a			)
												visited.append(_a			)
												_a      :       Any   =						-2
												_a      :       Optional[int]   =						[]
												_a      :       str   =						s
												_a      :       List[Any]   =						False
												_a      :       Optional[int]   =						set()

												while True:
																	# check if there is any non isolated nodes
																	if len(self.graph[s]			) != 0:
																						_a      :       Optional[Any]   =						s
																						for node in self.graph[s]:
																											if (
																											    visited.count(node[1]			) > 0
																											    and node[1] != parent
																											    and indirect_parents.count(node[1]			) > 0
																											    and not on_the_way_back
																											):
																																_a      :       int   =						len(_a			) - 1
																																while len_stack >= 0:
																																					if stack[len_stack] == node[1]:
																																										anticipating_nodes.add(node[1]			)
																																										break
																																					else:
																																										anticipating_nodes.add(stack[len_stack]			)
																																										len_stack -= 1
																											if visited.count(node[1]			) < 1:
																																stack.append(node[1]			)
																																visited.append(node[1]			)
																																_a      :       Optional[int]   =						node[1]
																																break

            # check if all the children are visited
																	if s == ss:
																						stack.pop()
																						_a      :       Union[str, Any]   =						True
																						if len(_a			) != 0:
																											_a      :       Any   =						stack[len(_a			) - 1]
																	else:
																						_a      :       Optional[int]   =						False
																						indirect_parents.append(_a			)
																						_a      :       Dict   =						s
																						_a      :       Union[str, Any]   =						ss

																	# check if se have reached the starting point
																	if len(_a			) == 0:
																						return list(_a			)


							def 							__lowercase							(     self			)       ->       Any:
												_a      :       Any   =						[]
												_a      :       Union[str, Any]   =						[]
												_a      :       List[str]   =						list(self.graph			)[0]
												stack.append(_a			)
												visited.append(_a			)
												_a      :       List[str]   =						-2
												_a      :       Dict   =						[]
												_a      :       str   =						s
												_a      :       Optional[Any]   =						False
												_a      :       str   =						set()

												while True:
																	# check if there is any non isolated nodes
																	if len(self.graph[s]			) != 0:
																						_a      :       str   =						s
																						for node in self.graph[s]:
																											if (
																											    visited.count(node[1]			) > 0
																											    and node[1] != parent
																											    and indirect_parents.count(node[1]			) > 0
																											    and not on_the_way_back
																											):
																																_a      :       int   =						len(_a			) - 1
																																while len_stack_minus_one >= 0:
																																					if stack[len_stack_minus_one] == node[1]:
																																										anticipating_nodes.add(node[1]			)
																																										break
																																					else:
																																										return True
																											if visited.count(node[1]			) < 1:
																																stack.append(node[1]			)
																																visited.append(node[1]			)
																																_a      :       Any   =						node[1]
																																break

            # check if all the children are visited
																	if s == ss:
																						stack.pop()
																						_a      :       Optional[Any]   =						True
																						if len(_a			) != 0:
																											_a      :       Tuple   =						stack[len(_a			) - 1]
																	else:
																						_a      :       Union[str, Any]   =						False
																						indirect_parents.append(_a			)
																						_a      :       Union[str, Any]   =						s
																						_a      :       List[Any]   =						ss

																	# check if se have reached the starting point
																	if len(_a			) == 0:
																						return False


							def 							__lowercase							(     self			,				_a=-2			,				_a=-1			)       ->       List[str]:
												_a      :       Dict   =						time()
												self.dfs(_a			,				_a			)
												_a      :       Tuple   =						time()
												return end - begin




							def 							__lowercase							(     self			,				_a=-2			)       ->       Optional[int]:
												_a      :       int   =						time()
												self.bfs(_a			)
												_a      :       List[Any]   =						time()
												return end - begin



class 							UpperCAmelCase_						:
							"""simple docstring"""







							def __init__(     self			)       ->       Optional[Any]:
												_a      :       Union[str, Any]   =						{}


							def 							__lowercase							(     self			,				_a			,				_a			,				_a=1			)       ->       List[Any]:
												# check if the u exists
												if self.graph.get(_a			):
																	# if there already is a edge
																	if self.graph[u].count([w, v]			) == 0:
																						self.graph[u].append([w, v]			)
												else:
																	# if u does not exist
																	_a      :       int   =						[[w, v]]
												# add the other way
												if self.graph.get(_a			):
																	# if there already is a edge
																	if self.graph[v].count([w, u]			) == 0:
																						self.graph[v].append([w, u]			)
												else:
																	# if u does not exist
																	_a      :       int   =						[[w, u]]


							def 							__lowercase							(     self			,				_a			,				_a			)       ->       List[Any]:
												if self.graph.get(_a			):
																	for _ in self.graph[u]:
																						if _[1] == v:
																											self.graph[u].remove(_a			)
        # the other way round
												if self.graph.get(_a			):
																	for _ in self.graph[v]:
																						if _[1] == u:
																											self.graph[v].remove(_a			)


							def 							__lowercase							(     self			,				_a=-2			,				_a=-1			)       ->       Any:
												if s == d:
																	return []
												_a      :       str   =						[]
												_a      :       Optional[Any]   =						[]
												if s == -2:
																	_a      :       List[str]   =						list(self.graph			)[0]
												stack.append(_a			)
												visited.append(_a			)
												_a      :       List[Any]   =						s

												while True:
																	# check if there is any non isolated nodes
																	if len(self.graph[s]			) != 0:
																						_a      :       Optional[Any]   =						s
																						for node in self.graph[s]:
																											if visited.count(node[1]			) < 1:
																																if node[1] == d:
																																					visited.append(_a			)
																																					return visited
																																else:
																																					stack.append(node[1]			)
																																					visited.append(node[1]			)
																																					_a      :       Optional[Any]   =						node[1]
																																					break

            # check if all the children are visited
																	if s == ss:
																						stack.pop()
																						if len(_a			) != 0:
																											_a      :       Dict   =						stack[len(_a			) - 1]
																	else:
																						_a      :       Union[str, Any]   =						ss

																	# check if se have reached the starting point
																	if len(_a			) == 0:
																						return visited


							def 							__lowercase							(     self			,				_a=-1			)       ->       int:
												if c == -1:
																	_a      :       Any   =						floor(random() * 1_0_0_0_0			) + 1_0
												for i in range(_a			):
																	# every vertex has max 100 edges
																	for _ in range(floor(random() * 1_0_2			) + 1			):
																						_a      :       Optional[Any]   =						floor(random() * c			) + 1
																						if n != i:
																											self.add_pair(_a			,				_a			,				1			)


							def 							__lowercase							(     self			,				_a=-2			)       ->       Tuple:
												_a      :       Optional[Any]   =						deque()
												_a      :       List[Any]   =						[]
												if s == -2:
																	_a      :       int   =						list(self.graph			)[0]
												d.append(_a			)
												visited.append(_a			)
												while d:
																	_a      :       List[Any]   =						d.popleft()
																	if len(self.graph[s]			) != 0:
																						for node in self.graph[s]:
																											if visited.count(node[1]			) < 1:
																																d.append(node[1]			)
																																visited.append(node[1]			)
												return visited


							def 							__lowercase							(     self			,				_a			)       ->       Optional[Any]:
												return len(self.graph[u]			)


							def 							__lowercase							(     self			)       ->       List[Any]:
												_a      :       List[str]   =						[]
												_a      :       Optional[Any]   =						[]
												_a      :       str   =						list(self.graph			)[0]
												stack.append(_a			)
												visited.append(_a			)
												_a      :       Any   =						-2
												_a      :       int   =						[]
												_a      :       Optional[Any]   =						s
												_a      :       str   =						False
												_a      :       Optional[Any]   =						set()

												while True:
																	# check if there is any non isolated nodes
																	if len(self.graph[s]			) != 0:
																						_a      :       List[Any]   =						s
																						for node in self.graph[s]:
																											if (
																											    visited.count(node[1]			) > 0
																											    and node[1] != parent
																											    and indirect_parents.count(node[1]			) > 0
																											    and not on_the_way_back
																											):
																																_a      :       Optional[int]   =						len(_a			) - 1
																																while len_stack >= 0:
																																					if stack[len_stack] == node[1]:
																																										anticipating_nodes.add(node[1]			)
																																										break
																																					else:
																																										anticipating_nodes.add(stack[len_stack]			)
																																										len_stack -= 1
																											if visited.count(node[1]			) < 1:
																																stack.append(node[1]			)
																																visited.append(node[1]			)
																																_a      :       int   =						node[1]
																																break

            # check if all the children are visited
																	if s == ss:
																						stack.pop()
																						_a      :       str   =						True
																						if len(_a			) != 0:
																											_a      :       List[Any]   =						stack[len(_a			) - 1]
																	else:
																						_a      :       List[Any]   =						False
																						indirect_parents.append(_a			)
																						_a      :       Tuple   =						s
																						_a      :       Tuple   =						ss

																	# check if se have reached the starting point
																	if len(_a			) == 0:
																						return list(_a			)


							def 							__lowercase							(     self			)       ->       List[str]:
												_a      :       str   =						[]
												_a      :       Optional[int]   =						[]
												_a      :       List[Any]   =						list(self.graph			)[0]
												stack.append(_a			)
												visited.append(_a			)
												_a      :       Tuple   =						-2
												_a      :       List[Any]   =						[]
												_a      :       Dict   =						s
												_a      :       List[str]   =						False
												_a      :       Optional[Any]   =						set()

												while True:
																	# check if there is any non isolated nodes
																	if len(self.graph[s]			) != 0:
																						_a      :       Optional[int]   =						s
																						for node in self.graph[s]:
																											if (
																											    visited.count(node[1]			) > 0
																											    and node[1] != parent
																											    and indirect_parents.count(node[1]			) > 0
																											    and not on_the_way_back
																											):
																																_a      :       Union[str, Any]   =						len(_a			) - 1
																																while len_stack_minus_one >= 0:
																																					if stack[len_stack_minus_one] == node[1]:
																																										anticipating_nodes.add(node[1]			)
																																										break
																																					else:
																																										return True
																											if visited.count(node[1]			) < 1:
																																stack.append(node[1]			)
																																visited.append(node[1]			)
																																_a      :       Union[str, Any]   =						node[1]
																																break

            # check if all the children are visited
																	if s == ss:
																						stack.pop()
																						_a      :       Union[str, Any]   =						True
																						if len(_a			) != 0:
																											_a      :       Optional[Any]   =						stack[len(_a			) - 1]
																	else:
																						_a      :       List[str]   =						False
																						indirect_parents.append(_a			)
																						_a      :       Dict   =						s
																						_a      :       str   =						ss

																	# check if se have reached the starting point
																	if len(_a			) == 0:
																						return False


							def 							__lowercase							(     self			)       ->       Union[str, Any]:
												return list(self.graph			)


							def 							__lowercase							(     self			,				_a=-2			,				_a=-1			)       ->       Union[str, Any]:
												_a      :       Optional[Any]   =						time()
												self.dfs(_a			,				_a			)
												_a      :       str   =						time()
												return end - begin




							def 							__lowercase							(     self			,				_a=-2			)       ->       Dict:
												_a      :       Union[str, Any]   =						time()
												self.bfs(_a			)
												_a      :       Optional[int]   =						time()
												return end - begin










"""simple docstring"""



import absl  # noqa: F401 # Here to have a nice missing dependency error message early on
import nltk  # noqa: F401 # Here to have a nice missing dependency error message early on
import numpy  # noqa: F401 # Here to have a nice missing dependency error message early on
import six  # noqa: F401 # Here to have a nice missing dependency error message early on
from rouge_score import rouge_scorer, scoring

import datasets


a_					=     """\
@inproceedings{lin-2004-rouge,
    title = \"{ROUGE}: A Package for Automatic Evaluation of Summaries\",
    author = \"Lin, Chin-Yew\",
    booktitle = \"Text Summarization Branches Out\",
    month = jul,
    year = \"2004\",
    address = \"Barcelona, Spain\",
    publisher = \"Association for Computational Linguistics\",
    url = \"https://www.aclweb.org/anthology/W04-1013\",
    pages = \"74--81\",
}
"""

a_					=     """\
ROUGE, or Recall-Oriented Understudy for Gisting Evaluation, is a set of metrics and a software package used for
evaluating automatic summarization and machine translation software in natural language processing.
The metrics compare an automatically produced summary or translation against a reference or a set of references (human-produced) summary or translation.

Note that ROUGE is case insensitive, meaning that upper case letters are treated the same way as lower case letters.

This metrics is a wrapper around Google Research reimplementation of ROUGE:
https://github.com/google-research/google-research/tree/master/rouge
"""

a_					=     """
Calculates average rouge scores for a list of hypotheses and references
Args:
    predictions: list of predictions to score. Each prediction
        should be a string with tokens separated by spaces.
    references: list of reference for each prediction. Each
        reference should be a string with tokens separated by spaces.
    rouge_types: A list of rouge types to calculate.
        Valid names:
        `\"rouge{n}\"` (e.g. `\"rouge1\"`, `\"rouge2\"`) where: {n} is the n-gram based scoring,
        `\"rougeL\"`: Longest common subsequence based scoring.
        `\"rougeLSum\"`: rougeLsum splits text using `\"\n\"`.
        See details in https://github.com/huggingface/datasets/issues/617
    use_stemmer: Bool indicating whether Porter stemmer should be used to strip word suffixes.
    use_aggregator: Return aggregates if this is set to True
Returns:
    rouge1: rouge_1 (precision, recall, f1),
    rouge2: rouge_2 (precision, recall, f1),
    rougeL: rouge_l (precision, recall, f1),
    rougeLsum: rouge_lsum (precision, recall, f1)
Examples:

    >>> rouge = datasets.load_metric('rouge')
    >>> predictions = [\"hello there\", \"general kenobi\"]
    >>> references = [\"hello there\", \"general kenobi\"]
    >>> results = rouge.compute(predictions=predictions, references=references)
    >>> print(list(results.keys()))
    ['rouge1', 'rouge2', 'rougeL', 'rougeLsum']
    >>> print(results[\"rouge1\"])
    AggregateScore(low=Score(precision=1.0, recall=1.0, fmeasure=1.0), mid=Score(precision=1.0, recall=1.0, fmeasure=1.0), high=Score(precision=1.0, recall=1.0, fmeasure=1.0))
    >>> print(results[\"rouge1\"].mid.fmeasure)
    1.0
"""






@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION				,				_KWARGS_DESCRIPTION	)
class 						__snake_case   (						datasets.Metric	):





 """simple docstring"""


 def    UpperCamelCase__(       self    ):



     '''simple docstring'''




     return datasets.MetricInfo(
         description=_DESCRIPTION   ,		citation=_CITATION   ,		inputs_description=_KWARGS_DESCRIPTION   ,		features=datasets.Features(
             {
                 '''predictions''': datasets.Value('''string'''   ,		id='''sequence'''    ),
                 '''references''': datasets.Value('''string'''   ,		id='''sequence'''    ),
             }    )   ,		codebase_urls=['''https://github.com/google-research/google-research/tree/master/rouge''']   ,		reference_urls=[
             '''https://en.wikipedia.org/wiki/ROUGE_(metric)''',
             '''https://github.com/google-research/google-research/tree/master/rouge''',
         ]   ,		)







 def    UpperCamelCase__(       self   ,		__lowerCamelCase   ,		__lowerCamelCase   ,		__lowerCamelCase=None   ,		__lowerCamelCase=True   ,		__lowerCamelCase=False    ):



     '''simple docstring'''




     if rouge_types is None:
         __A       :		Dict							=	['''rouge1''', '''rouge2''', '''rougeL''', '''rougeLsum''']

     __A       :		Dict							=	rouge_scorer.RougeScorer(rouge_types=__lowerCamelCase   ,		use_stemmer=__lowerCamelCase    )
     if use_aggregator:
         __A       :		Dict							=	scoring.BootstrapAggregator()
     else:
         __A       :		Optional[Any]							=	[]

     for ref, pred in zip(__lowerCamelCase   ,		__lowerCamelCase    ):
         __A       :		List[Any]							=	scorer.score(__lowerCamelCase   ,		__lowerCamelCase    )
         if use_aggregator:
             aggregator.add_scores(__lowerCamelCase    )
         else:
             scores.append(__lowerCamelCase    )

     if use_aggregator:
         __A       :		Optional[Any]							=	aggregator.aggregate()
     else:
         __A       :		List[Any]							=	{}
         for key in scores[0]:
             __A       :		Tuple							=	[score[key] for score in scores]

     return result




