


"""simple docstring"""
# using dfs for finding eulerian path traversal







def 						_a				(      _SCREAMING_SNAKE_CASE				, _SCREAMING_SNAKE_CASE				, _SCREAMING_SNAKE_CASE				, _SCREAMING_SNAKE_CASE=None				)    ->				Dict:
							snake_case_           =		(path or []) + [u]
							for v in graph[u]:
														if visited_edge[u][v] is False:
																					snake_case_       ,						snake_case_           =		True, True
																					snake_case_           =		dfs(_SCREAMING_SNAKE_CASE				, _SCREAMING_SNAKE_CASE				, _SCREAMING_SNAKE_CASE				, _SCREAMING_SNAKE_CASE				)
							return path







def 						_a				(      _SCREAMING_SNAKE_CASE				, _SCREAMING_SNAKE_CASE				)    ->				List[Any]:
							snake_case_           =		0
							snake_case_           =		-1
							for i in range(_SCREAMING_SNAKE_CASE				):
														if i not in graph.keys():
																					continue
														if len(graph[i]				) % 2 == 1:
																					odd_degree_nodes += 1
																					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 						_a				(      _SCREAMING_SNAKE_CASE				, _SCREAMING_SNAKE_CASE				)    ->				str:
							snake_case_           =		[[False for _ in range(max_node + 1				)] for _ in range(max_node + 1				)]
							snake_case_       ,						snake_case_           =		check_circuit_or_path(_SCREAMING_SNAKE_CASE				, _SCREAMING_SNAKE_CASE				)
							if check == 3:
														print("""graph is not Eulerian"""				)
														print("""no path"""				)
														return
							snake_case_           =		1
							if check == 2:
														snake_case_           =		odd_node
														print("""graph has a Euler path"""				)
							if check == 1:
														print("""graph has a Euler cycle"""				)
							snake_case_           =		dfs(_SCREAMING_SNAKE_CASE				, _SCREAMING_SNAKE_CASE				, _SCREAMING_SNAKE_CASE				)
							print(_SCREAMING_SNAKE_CASE				)







def 						_a				(      )    ->				Any:
							snake_case_           =		{1: [2, 3, 4], 2: [1, 3], 3: [1, 2], 4: [1, 5], 5: [4]}
							snake_case_           =		{1: [2, 3, 4, 5], 2: [1, 3], 3: [1, 2], 4: [1, 5], 5: [1, 4]}
							snake_case_           =		{1: [2, 3, 4], 2: [1, 3, 4], 3: [1, 2], 4: [1, 2, 5], 5: [4]}
							snake_case_           =		{1: [2, 3], 2: [1, 3], 3: [1, 2]}
							snake_case_           =		{
							    1: [],
							    2: []
							    # all degree is zero
							}
							snake_case_           =		10
							check_euler(_SCREAMING_SNAKE_CASE				, _SCREAMING_SNAKE_CASE				)
							check_euler(_SCREAMING_SNAKE_CASE				, _SCREAMING_SNAKE_CASE				)
							check_euler(_SCREAMING_SNAKE_CASE				, _SCREAMING_SNAKE_CASE				)
							check_euler(_SCREAMING_SNAKE_CASE				, _SCREAMING_SNAKE_CASE				)
							check_euler(_SCREAMING_SNAKE_CASE				, _SCREAMING_SNAKE_CASE				)


if __name__ == "__main__":
				main()







"""simple docstring"""
from __future__ import annotations

from collections import deque





class      __A     :





							'''simple docstring'''

							def __init__(				self							:      List[Any]		,       UpperCAmelCase_							:      list[str]       )					->List[Any]:



														"""simple docstring"""



														snake_case_           =		[]
														self.adlist.append(
														    {"""value""": """""", """next_states""": [], """fail_state""": 0, """output""": []}       )

														for keyword in keywords:
																					self.add_keyword(UpperCAmelCase_       )
														self.set_fail_transitions()



							def 		lowerCAmelCase       (				self							:      int		,       UpperCAmelCase_							:      int		,       UpperCAmelCase_							:      str       )					->int | None:



														"""simple docstring"""



														for state in self.adlist[current_state]["next_states"]:
																					if char == self.adlist[state]["value"]:
																												return state
														return None



							def 		lowerCAmelCase       (				self							:      int		,       UpperCAmelCase_							:      str       )					->None:



														"""simple docstring"""



														snake_case_           =		0
														for character in keyword:
																					snake_case_           =		self.find_next_state(UpperCAmelCase_		,       UpperCAmelCase_       )
																					if next_state is None:
																												self.adlist.append(
																												    {
																												        """value""": character,
																												        """next_states""": [],
																												        """fail_state""": 0,
																												        """output""": [],
																												    }       )
																												self.adlist[current_state]["next_states"].append(len(self.adlist       ) - 1       )
																												snake_case_           =		len(self.adlist       ) - 1
																					else:
																												snake_case_           =		next_state
														self.adlist[current_state]["output"].append(UpperCAmelCase_       )



							def 		lowerCAmelCase       (				self							:      Optional[Any]       )					->None:



														"""simple docstring"""



														snake_case_           =		deque()
														for node in self.adlist[0]["next_states"]:
																					q.append(UpperCAmelCase_       )
																					snake_case_           =		0
														while q:
																					snake_case_           =		q.popleft()
																					for child in self.adlist[r]["next_states"]:
																												q.append(UpperCAmelCase_       )
																												snake_case_           =		self.adlist[r]["""fail_state"""]
																												while (
																												    self.find_next_state(UpperCAmelCase_		,       self.adlist[child]["""value"""]       ) is None
																												    and state != 0
																												):
																																			snake_case_           =		self.adlist[state]["""fail_state"""]
																												snake_case_           =		self.find_next_state(
																												    UpperCAmelCase_		,       self.adlist[child]["""value"""]       )
																												if self.adlist[child]["fail_state"] is None:
																																			snake_case_           =		0
																												snake_case_           =		(
																												    self.adlist[child]["""output"""]
																												    + self.adlist[self.adlist[child]["""fail_state"""]]["""output"""]
																												)



							def 		lowerCAmelCase       (				self							:      Union[str, Any]		,       UpperCAmelCase_							:      str       )					->dict[str, list[int]]:



														"""simple docstring"""



														snake_case_           =		{}  # returns a dict with keywords and list of its occurrences
														snake_case_           =		0
														for i in range(len(UpperCAmelCase_       )       ):
																					while (
																					    self.find_next_state(UpperCAmelCase_		,       string[i]       ) is None
																					    and current_state != 0
																					):
																												snake_case_           =		self.adlist[current_state]["""fail_state"""]
																					snake_case_           =		self.find_next_state(UpperCAmelCase_		,       string[i]       )
																					if next_state is None:
																												snake_case_           =		0
																					else:
																												snake_case_           =		next_state
																												for key in self.adlist[current_state]["output"]:
																																			if key not in result:
																																										snake_case_           =		[]
																																			result[key].append(i - len(UpperCAmelCase_       ) + 1       )
														return result


if __name__ == "__main__":
				import doctest

				doctest.testmod()



