
"""simple docstring"""




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



class 	lowerCAmelCase_						:


				"""simple docstring"""



				def __init__(self    )					->		Union[str, Any]:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__						:       Any           =   {}



				def 	__magic_name__    (self   ,       SCREAMING_SNAKE_CASE__   ,       SCREAMING_SNAKE_CASE__   ,       SCREAMING_SNAKE_CASE__=1    )					->		str:



											"""simple docstring"""




											if self.graph.get(SCREAMING_SNAKE_CASE__    ):
																		if self.graph[u].count([w, v]    ) == 0:
																									self.graph[u].append([w, v]    )
											else:
																		SCREAMING_SNAKE_CASE__						:       Any           =   [[w, v]]
											if not self.graph.get(SCREAMING_SNAKE_CASE__    ):
																		SCREAMING_SNAKE_CASE__						:       List[str]           =   []



				def 	__magic_name__    (self    )					->		List[Any]:



											"""simple docstring"""




											return list(self.graph    )



				def 	__magic_name__    (self   ,       SCREAMING_SNAKE_CASE__   ,       SCREAMING_SNAKE_CASE__    )					->		str:



											"""simple docstring"""




											if self.graph.get(SCREAMING_SNAKE_CASE__    ):
																		for _ in self.graph[u]:
																									if _[1] == v:
																																self.graph[u].remove(SCREAMING_SNAKE_CASE__    )



				def 	__magic_name__    (self   ,       SCREAMING_SNAKE_CASE__=-2   ,       SCREAMING_SNAKE_CASE__=-1    )					->		Dict:



											"""simple docstring"""




											if s == d:
																		return []
											SCREAMING_SNAKE_CASE__						:       int           =   []
											SCREAMING_SNAKE_CASE__						:       Tuple           =   []
											if s == -2:
																		SCREAMING_SNAKE_CASE__						:       Any           =   list(self.graph    )[0]
											stack.append(SCREAMING_SNAKE_CASE__    )
											visited.append(SCREAMING_SNAKE_CASE__    )
											SCREAMING_SNAKE_CASE__						:       Union[str, Any]           =   s

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

            # check if all the children are visited
																		if s == ss:
																									stack.pop()
																									if len(SCREAMING_SNAKE_CASE__    ) != 0:
																																SCREAMING_SNAKE_CASE__						:       Optional[int]           =   stack[len(SCREAMING_SNAKE_CASE__    ) - 1]
																		else:
																									SCREAMING_SNAKE_CASE__						:       Tuple           =   ss

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



				def 	__magic_name__    (self   ,       SCREAMING_SNAKE_CASE__=-1    )					->		int:



											"""simple docstring"""




											if c == -1:
																		SCREAMING_SNAKE_CASE__						:       int           =   floor(random() * 1_00_00    ) + 10
											for i in range(SCREAMING_SNAKE_CASE__    ):
																		# every vertex has max 100 edges
																		for _ in range(floor(random() * 1_02    ) + 1    ):
																									SCREAMING_SNAKE_CASE__						:       Tuple           =   floor(random() * c    ) + 1
																									if n != i:
																																self.add_pair(SCREAMING_SNAKE_CASE__   ,       SCREAMING_SNAKE_CASE__   ,       1    )



				def 	__magic_name__    (self   ,       SCREAMING_SNAKE_CASE__=-2    )					->		List[str]:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__						:       Optional[int]           =   deque()
											SCREAMING_SNAKE_CASE__						:       str           =   []
											if s == -2:
																		SCREAMING_SNAKE_CASE__						:       str           =   list(self.graph    )[0]
											d.append(SCREAMING_SNAKE_CASE__    )
											visited.append(SCREAMING_SNAKE_CASE__    )
											while d:
																		SCREAMING_SNAKE_CASE__						:       Dict           =   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 	__magic_name__    (self   ,       SCREAMING_SNAKE_CASE__    )					->		Optional[int]:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__						:       int           =   0
											for x in self.graph:
																		for y in self.graph[x]:
																									if y[1] == u:
																																count += 1
											return count



				def 	__magic_name__    (self   ,       SCREAMING_SNAKE_CASE__    )					->		str:



											"""simple docstring"""




											return len(self.graph[u]    )



				def 	__magic_name__    (self   ,       SCREAMING_SNAKE_CASE__=-2    )					->		Union[str, Any]:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__						:       Any           =   []
											SCREAMING_SNAKE_CASE__						:       Dict           =   []
											if s == -2:
																		SCREAMING_SNAKE_CASE__						:       Any           =   list(self.graph    )[0]
											stack.append(SCREAMING_SNAKE_CASE__    )
											visited.append(SCREAMING_SNAKE_CASE__    )
											SCREAMING_SNAKE_CASE__						:       List[Any]           =   s
											SCREAMING_SNAKE_CASE__						:       Optional[Any]           =   []

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

            # check if all the children are visited
																		if s == ss:
																									sorted_nodes.append(stack.pop()    )
																									if len(SCREAMING_SNAKE_CASE__    ) != 0:
																																SCREAMING_SNAKE_CASE__						:       Optional[int]           =   stack[len(SCREAMING_SNAKE_CASE__    ) - 1]
																		else:
																									SCREAMING_SNAKE_CASE__						:       Optional[int]           =   ss

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



				def 	__magic_name__    (self    )					->		Tuple:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__						:       Optional[int]           =   []
											SCREAMING_SNAKE_CASE__						:       Tuple           =   []
											SCREAMING_SNAKE_CASE__						:       List[Any]           =   list(self.graph    )[0]
											stack.append(SCREAMING_SNAKE_CASE__    )
											visited.append(SCREAMING_SNAKE_CASE__    )
											SCREAMING_SNAKE_CASE__						:       Tuple           =   -2
											SCREAMING_SNAKE_CASE__						:       int           =   []
											SCREAMING_SNAKE_CASE__						:       int           =   s
											SCREAMING_SNAKE_CASE__						:       Optional[Any]           =   False
											SCREAMING_SNAKE_CASE__						:       Union[str, Any]           =   set()

											while True:
																		# check if there is any non isolated nodes
																		if len(self.graph[s]    ) != 0:
																									SCREAMING_SNAKE_CASE__						:       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
																																):
																																							SCREAMING_SNAKE_CASE__						:       Tuple           =   len(SCREAMING_SNAKE_CASE__    ) - 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]    )
																																							SCREAMING_SNAKE_CASE__						:       List[str]           =   node[1]
																																							break

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

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



				def 	__magic_name__    (self    )					->		int:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__						:       Optional[int]           =   []
											SCREAMING_SNAKE_CASE__						:       Dict           =   []
											SCREAMING_SNAKE_CASE__						:       Optional[Any]           =   list(self.graph    )[0]
											stack.append(SCREAMING_SNAKE_CASE__    )
											visited.append(SCREAMING_SNAKE_CASE__    )
											SCREAMING_SNAKE_CASE__						:       Union[str, Any]           =   -2
											SCREAMING_SNAKE_CASE__						:       Optional[Any]           =   []
											SCREAMING_SNAKE_CASE__						:       Optional[int]           =   s
											SCREAMING_SNAKE_CASE__						:       Tuple           =   False
											SCREAMING_SNAKE_CASE__						:       Tuple           =   set()

											while True:
																		# check if there is any non isolated nodes
																		if len(self.graph[s]    ) != 0:
																									SCREAMING_SNAKE_CASE__						:       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
																																):
																																							SCREAMING_SNAKE_CASE__						:       Any           =   len(SCREAMING_SNAKE_CASE__    ) - 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]    )
																																							SCREAMING_SNAKE_CASE__						:       Union[str, Any]           =   node[1]
																																							break

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

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



				def 	__magic_name__    (self   ,       SCREAMING_SNAKE_CASE__=-2   ,       SCREAMING_SNAKE_CASE__=-1    )					->		str:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__						:       List[str]           =   time()
											self.dfs(SCREAMING_SNAKE_CASE__   ,       SCREAMING_SNAKE_CASE__    )
											SCREAMING_SNAKE_CASE__						:       Dict           =   time()
											return end - begin



				def 	__magic_name__    (self   ,       SCREAMING_SNAKE_CASE__=-2    )					->		List[str]:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__						:       int           =   time()
											self.bfs(SCREAMING_SNAKE_CASE__    )
											SCREAMING_SNAKE_CASE__						:       Tuple           =   time()
											return end - begin






class 	lowerCAmelCase_						:


				"""simple docstring"""



				def __init__(self    )					->		List[Any]:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__						:       Optional[Any]           =   {}



				def 	__magic_name__    (self   ,       SCREAMING_SNAKE_CASE__   ,       SCREAMING_SNAKE_CASE__   ,       SCREAMING_SNAKE_CASE__=1    )					->		int:



											"""simple docstring"""




											if self.graph.get(SCREAMING_SNAKE_CASE__    ):
																		# 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
																		SCREAMING_SNAKE_CASE__						:       Any           =   [[w, v]]
											# add the other way
											if self.graph.get(SCREAMING_SNAKE_CASE__    ):
																		# 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
																		SCREAMING_SNAKE_CASE__						:       Optional[Any]           =   [[w, u]]



				def 	__magic_name__    (self   ,       SCREAMING_SNAKE_CASE__   ,       SCREAMING_SNAKE_CASE__    )					->		Optional[int]:



											"""simple docstring"""




											if self.graph.get(SCREAMING_SNAKE_CASE__    ):
																		for _ in self.graph[u]:
																									if _[1] == v:
																																self.graph[u].remove(SCREAMING_SNAKE_CASE__    )
        # the other way round
											if self.graph.get(SCREAMING_SNAKE_CASE__    ):
																		for _ in self.graph[v]:
																									if _[1] == u:
																																self.graph[v].remove(SCREAMING_SNAKE_CASE__    )



				def 	__magic_name__    (self   ,       SCREAMING_SNAKE_CASE__=-2   ,       SCREAMING_SNAKE_CASE__=-1    )					->		Optional[int]:



											"""simple docstring"""




											if s == d:
																		return []
											SCREAMING_SNAKE_CASE__						:       Any           =   []
											SCREAMING_SNAKE_CASE__						:       str           =   []
											if s == -2:
																		SCREAMING_SNAKE_CASE__						:       Optional[Any]           =   list(self.graph    )[0]
											stack.append(SCREAMING_SNAKE_CASE__    )
											visited.append(SCREAMING_SNAKE_CASE__    )
											SCREAMING_SNAKE_CASE__						:       Optional[Any]           =   s

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

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

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



				def 	__magic_name__    (self   ,       SCREAMING_SNAKE_CASE__=-1    )					->		Tuple:



											"""simple docstring"""




											if c == -1:
																		SCREAMING_SNAKE_CASE__						:       Dict           =   floor(random() * 1_00_00    ) + 10
											for i in range(SCREAMING_SNAKE_CASE__    ):
																		# every vertex has max 100 edges
																		for _ in range(floor(random() * 1_02    ) + 1    ):
																									SCREAMING_SNAKE_CASE__						:       str           =   floor(random() * c    ) + 1
																									if n != i:
																																self.add_pair(SCREAMING_SNAKE_CASE__   ,       SCREAMING_SNAKE_CASE__   ,       1    )



				def 	__magic_name__    (self   ,       SCREAMING_SNAKE_CASE__=-2    )					->		Optional[Any]:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__						:       List[Any]           =   deque()
											SCREAMING_SNAKE_CASE__						:       int           =   []
											if s == -2:
																		SCREAMING_SNAKE_CASE__						:       str           =   list(self.graph    )[0]
											d.append(SCREAMING_SNAKE_CASE__    )
											visited.append(SCREAMING_SNAKE_CASE__    )
											while d:
																		SCREAMING_SNAKE_CASE__						:       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 	__magic_name__    (self   ,       SCREAMING_SNAKE_CASE__    )					->		str:



											"""simple docstring"""




											return len(self.graph[u]    )



				def 	__magic_name__    (self    )					->		Union[str, Any]:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__						:       Optional[int]           =   []
											SCREAMING_SNAKE_CASE__						:       int           =   []
											SCREAMING_SNAKE_CASE__						:       Union[str, Any]           =   list(self.graph    )[0]
											stack.append(SCREAMING_SNAKE_CASE__    )
											visited.append(SCREAMING_SNAKE_CASE__    )
											SCREAMING_SNAKE_CASE__						:       int           =   -2
											SCREAMING_SNAKE_CASE__						:       Tuple           =   []
											SCREAMING_SNAKE_CASE__						:       Optional[Any]           =   s
											SCREAMING_SNAKE_CASE__						:       Optional[int]           =   False
											SCREAMING_SNAKE_CASE__						:       int           =   set()

											while True:
																		# check if there is any non isolated nodes
																		if len(self.graph[s]    ) != 0:
																									SCREAMING_SNAKE_CASE__						:       Union[str, 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
																																):
																																							SCREAMING_SNAKE_CASE__						:       Any           =   len(SCREAMING_SNAKE_CASE__    ) - 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]    )
																																							SCREAMING_SNAKE_CASE__						:       Optional[int]           =   node[1]
																																							break

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

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



				def 	__magic_name__    (self    )					->		List[Any]:



											"""simple docstring"""




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

											while True:
																		# check if there is any non isolated nodes
																		if len(self.graph[s]    ) != 0:
																									SCREAMING_SNAKE_CASE__						:       Tuple           =   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
																																):
																																							SCREAMING_SNAKE_CASE__						:       str           =   len(SCREAMING_SNAKE_CASE__    ) - 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]    )
																																							SCREAMING_SNAKE_CASE__						:       Union[str, Any]           =   node[1]
																																							break

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

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



				def 	__magic_name__    (self    )					->		Optional[int]:



											"""simple docstring"""




											return list(self.graph    )



				def 	__magic_name__    (self   ,       SCREAMING_SNAKE_CASE__=-2   ,       SCREAMING_SNAKE_CASE__=-1    )					->		Any:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__						:       List[Any]           =   time()
											self.dfs(SCREAMING_SNAKE_CASE__   ,       SCREAMING_SNAKE_CASE__    )
											SCREAMING_SNAKE_CASE__						:       Any           =   time()
											return end - begin



				def 	__magic_name__    (self   ,       SCREAMING_SNAKE_CASE__=-2    )					->		Optional[int]:



											"""simple docstring"""




											SCREAMING_SNAKE_CASE__						:       Any           =   time()
											self.bfs(SCREAMING_SNAKE_CASE__    )
											SCREAMING_SNAKE_CASE__						:       Any           =   time()
											return end - begin











"""simple docstring"""



# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import torch

from ..models.auto import AutoModelForSequenceClassification, AutoTokenizer
from .base import PipelineTool






class 		__snake_case					(		SCREAMING_SNAKE_CASE__     ):





 """simple docstring"""


 _lowerCamelCase        =     """facebook/bart-large-mnli"""
 _lowerCamelCase        =     (
     """This is a tool that classifies an English text using provided labels. It takes two inputs: `text`, which """
     """should be the text to classify, and `labels`, which should be the list of labels to use for classification. """
     """It returns the most likely label in the list of provided `labels` for the input text."""
 )
 _lowerCamelCase        =     """text_classifier"""
 _lowerCamelCase        =     AutoTokenizer
 _lowerCamelCase        =     AutoModelForSequenceClassification

 _lowerCamelCase        =     ["""text""", ["""text"""]]
 _lowerCamelCase        =     ["""text"""]

 def 					UpperCamelCase__(    self  ):



     '''simple docstring'''




     super().setup()
     __A    :						List[str]						 =     self.model.config
     __A    :						int						 =     -1
     for idx, label in config.idalabel.items():
         if label.lower().startswith('''entail'''  ):
             __A    :						List[str]						 =     int(__lowerCamelCase  )
     if self.entailment_id == -1:
         raise ValueError('''Could not determine the entailment ID from the model config, please pass it at init.'''  )

 def 					UpperCamelCase__(    self					,						__lowerCamelCase					,						__lowerCamelCase  ):



     '''simple docstring'''




     __A    :						Union[str, Any]						 =     labels
     return self.pre_processor(
         [text] * len(__lowerCamelCase  )					,						[F"""This example is {label}""" for label in labels]					,						return_tensors='''pt'''					,						padding='''max_length'''					,						)







 def 					UpperCamelCase__(    self					,						__lowerCamelCase  ):



     '''simple docstring'''




     __A    :						List[Any]						 =     outputs.logits
     __A    :						List[str]						 =     torch.argmax(logits[:, 2]  ).item()
     return self._labels[label_id]




