


"""simple docstring"""







# using dfs for finding eulerian path traversal




def    UpperCAmelCase__       (lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_=None   ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						   =				(path or []) + [u]
					for v in graph[u]:
										if visited_edge[u][v] is False:
															__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				True, True
															__SCREAMING_SNAKE_CASE						   =				dfs(lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_   )
					return path




def    UpperCAmelCase__       (lowerCAmelCase_  ,						lowerCAmelCase_   ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						   =				0
					__SCREAMING_SNAKE_CASE						   =				-1
					for i in range(lowerCAmelCase_   ):
										if i not in graph.keys():
															continue
										if len(graph[i]   ) % 2 == 1:
															odd_degree_nodes += 1
															__SCREAMING_SNAKE_CASE						   =				i
					if odd_degree_nodes == 0:
										return 1, odd_node
					if odd_degree_nodes == 2:
										return 2, odd_node
					return 3, odd_node




def    UpperCAmelCase__       (lowerCAmelCase_  ,						lowerCAmelCase_   ):




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						   =				[[False for _ in range(max_node + 1   )] for _ in range(max_node + 1   )]
					__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				check_circuit_or_path(lowerCAmelCase_  ,						lowerCAmelCase_   )
					if check == 3:
										print("graph is not Eulerian"   )
										print("no path"   )
										return
					__SCREAMING_SNAKE_CASE						   =				1
					if check == 2:
										__SCREAMING_SNAKE_CASE						   =				odd_node
										print("graph has a Euler path"   )
					if check == 1:
										print("graph has a Euler cycle"   )
					__SCREAMING_SNAKE_CASE						   =				dfs(lowerCAmelCase_  ,						lowerCAmelCase_  ,						lowerCAmelCase_   )
					print(lowerCAmelCase_   )




def    UpperCAmelCase__       ():




					'''simple docstring'''


					__SCREAMING_SNAKE_CASE						   =				{1: [2, 3, 4], 2: [1, 3], 3: [1, 2], 4: [1, 5], 5: [4]}
					__SCREAMING_SNAKE_CASE						   =				{1: [2, 3, 4, 5], 2: [1, 3], 3: [1, 2], 4: [1, 5], 5: [1, 4]}
					__SCREAMING_SNAKE_CASE						   =				{1: [2, 3, 4], 2: [1, 3, 4], 3: [1, 2], 4: [1, 2, 5], 5: [4]}
					__SCREAMING_SNAKE_CASE						   =				{1: [2, 3], 2: [1, 3], 3: [1, 2]}
					__SCREAMING_SNAKE_CASE						   =				{
					    1: [],
					    2: []
					    # all degree is zero
					}
					__SCREAMING_SNAKE_CASE						   =				10
					check_euler(lowerCAmelCase_  ,						lowerCAmelCase_   )
					check_euler(lowerCAmelCase_  ,						lowerCAmelCase_   )
					check_euler(lowerCAmelCase_  ,						lowerCAmelCase_   )
					check_euler(lowerCAmelCase_  ,						lowerCAmelCase_   )
					check_euler(lowerCAmelCase_  ,						lowerCAmelCase_   )


if __name__ == "__main__":
		main()




"""simple docstring"""







import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
		import torch

		from transformers.generation import DisjunctiveConstraint




@require_torch
class  UpperCamelCase_	( unittest.TestCase):

	"""simple docstring"""





	def   UpperCAmelCase_      ( self			:				Optional[int]   )       ->	List[str]:
						# For consistency across different places the DisjunctiveConstraint is called,
						# dc.token_ids is a list of integers. It is also initialized only by integers.

						__SCREAMING_SNAKE_CASE						   =				[[1, 2, 4], [1, 2, 3, 4]]
						__SCREAMING_SNAKE_CASE						   =				DisjunctiveConstraint(UpperCAmelCase__   )
						self.assertTrue(isinstance(dc.token_ids			,			UpperCAmelCase__   )   )

						with self.assertRaises(UpperCAmelCase__   ):
											DisjunctiveConstraint(torch.LongTensor([[1, 2, 4], [1, 2, 3]]   )   )

						with self.assertRaises(UpperCAmelCase__   ):
											DisjunctiveConstraint([torch.LongTensor([1, 2, 4]   ), torch.LongTensor([1, 2, 3, 4, 5]   )]   )




	def   UpperCAmelCase_      ( self			:				Any   )       ->	int:
						# We can't have constraints that are complete subsets of another. This leads to a preverse
						# interpretation of "constraint fulfillment": does generating [1,2,3] fulfill the constraint?
						# It would mean that it generated [1,2] which fulfills it, but it's in the middle of potentially
						# fulfilling [1,2,3,4]. If we believe that [1,2,3] does fulfill the constraint, then the algorithm
						# will necessarily never reach [1,2,3,4], giving users a false sense of control (better to just not allow it).
						__SCREAMING_SNAKE_CASE						   =				[[1, 2], [1, 2, 3, 4]]

						with self.assertRaises(UpperCAmelCase__   ):
											DisjunctiveConstraint(UpperCAmelCase__   )  # fails here




	def   UpperCAmelCase_      ( self			:				List[Any]   )       ->	Any:
						__SCREAMING_SNAKE_CASE						   =				[[1, 2, 3], [1, 2, 4]]

						__SCREAMING_SNAKE_CASE						   =				DisjunctiveConstraint(UpperCAmelCase__   )

						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				dc.update(1   )
						__SCREAMING_SNAKE_CASE						   =				stepped is True and completed is False and reset is False
						self.assertTrue(UpperCAmelCase__   )
						self.assertTrue(not dc.completed   )
						self.assertTrue(dc.current_seq == [1]   )

						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				dc.update(2   )
						__SCREAMING_SNAKE_CASE						   =				stepped is True and completed is False and reset is False
						self.assertTrue(UpperCAmelCase__   )
						self.assertTrue(not dc.completed   )
						self.assertTrue(dc.current_seq == [1, 2]   )

						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				dc.update(3   )
						__SCREAMING_SNAKE_CASE						   =				stepped is True and completed is True and reset is False
						self.assertTrue(UpperCAmelCase__   )
						self.assertTrue(dc.completed   )  # Completed!
						self.assertTrue(dc.current_seq == [1, 2, 3]   )




	def   UpperCAmelCase_      ( self			:				str   )       ->	List[str]:
						__SCREAMING_SNAKE_CASE						   =				[[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

						__SCREAMING_SNAKE_CASE						   =				DisjunctiveConstraint(UpperCAmelCase__   )

						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				dc.update(1   )
						self.assertTrue(not dc.completed   )
						self.assertTrue(dc.current_seq == [1]   )

						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				dc.update(2   )
						self.assertTrue(not dc.completed   )
						self.assertTrue(dc.current_seq == [1, 2]   )

						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				dc.update(4   )
						self.assertTrue(not dc.completed   )
						self.assertTrue(dc.current_seq == [1, 2, 4]   )

						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				dc.update(5   )
						self.assertTrue(dc.completed   )  # Completed!
						self.assertTrue(dc.current_seq == [1, 2, 4, 5]   )

						dc.reset()

						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				dc.update(1   )
						self.assertTrue(not dc.completed   )
						self.assertTrue(dc.remaining() == 3   )
						self.assertTrue(dc.current_seq == [1]   )

						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				dc.update(2   )
						self.assertTrue(not dc.completed   )
						self.assertTrue(dc.remaining() == 2   )
						self.assertTrue(dc.current_seq == [1, 2]   )

						__SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE   ,  __SCREAMING_SNAKE_CASE						   =				dc.update(5   )
						self.assertTrue(dc.completed   )  # Completed!
						self.assertTrue(dc.remaining() == 0   )
						self.assertTrue(dc.current_seq == [1, 2, 5]   )
