import argparse
import glob
import importlib.util
import os
import re

import black
from doc_builder.style_doc import style_docstrings_in_code


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_copies.py
_lowerCAmelCase       =		"src/diffusers"
_lowerCAmelCase       =		"."


# This is to make sure the diffusers module imported is the one in the repo.
_lowerCAmelCase       =		importlib.util.spec_from_file_location(
    "diffusers",
    os.path.join(DIFFUSERS_PATH, "__init__.py"),
    submodule_search_locations=[DIFFUSERS_PATH],
)
_lowerCAmelCase       =		spec.loader.load_module()
def 					_snake_case	(  __snake_case  ,     __snake_case						):
					return line.startswith(__snake_case						) or len(__snake_case						) <= 1 or re.search(R'''^\s*\)(\s*->.*:|:)\s*$'''  ,     __snake_case						) is not None
def 					_snake_case	(  __snake_case						):
					_UpperCamelCase			     =     object_name.split('''.'''						)
					_UpperCamelCase			     =     0

					# First let's find the module where our object lives.
					_UpperCamelCase			     =     parts[i]
					while i < len(__snake_case						) and not os.path.isfile(os.path.join(__snake_case  ,     f"""{module}.py"""						)						):
										i += 1
										if i < len(__snake_case						):
															_UpperCamelCase			     =     os.path.join(__snake_case  ,     parts[i]						)
					if i >= len(__snake_case						):
										raise ValueError(f"""`object_name` should begin with the name of a module of diffusers but got {object_name}."""						)

					with open(os.path.join(__snake_case  ,     f"""{module}.py"""						)  ,     '''r'''  ,     encoding='''utf-8'''  ,     newline='''\n'''						) as f:
										_UpperCamelCase			     =     f.readlines()

					# Now let's find the class / func in the code!
					_UpperCamelCase			     =     ''''''
					_UpperCamelCase			     =     0
					for name in parts[i + 1 :]:
										while (
										    line_index < len(__snake_case						) and re.search(Rf"""^{indent}(class|def)\s+{name}(\(|\:)"""  ,     lines[line_index]						) is None
										):
															line_index += 1
										indent += "    "
										line_index += 1

					if line_index >= len(__snake_case						):
										raise ValueError(f""" {object_name} does not match any function or class in {module}."""						)

					# We found the beginning of the class / func, now let's find the end (when the indent diminishes).
					_UpperCamelCase			     =     line_index
					while line_index < len(__snake_case						) and _should_continue(lines[line_index]  ,     __snake_case						):
										line_index += 1
					# Clean up empty lines at the end (if any).
					while len(lines[line_index - 1]						) <= 1:
										line_index -= 1

					_UpperCamelCase			     =     lines[start_index:line_index]
					return "".join(__snake_case						)


_lowerCAmelCase       =		re.compile(r"^(\s*)#\s*Copied from\s+diffusers\.(\S+\.\S+)\s*($|\S.*$)")
_lowerCAmelCase       =		re.compile(r"^\s*(\S+)->(\S+)(\s+.*|$)")
_lowerCAmelCase       =		re.compile(r"<FILL\s+[^>]*>")
def 					_snake_case	(  __snake_case						):
					_UpperCamelCase			     =     code.split('''\n'''						)
					_UpperCamelCase			     =     0
					while idx < len(__snake_case						) and len(lines[idx]						) == 0:
										idx += 1
					if idx < len(__snake_case						):
										return re.search(R'''^(\s*)\S'''  ,     lines[idx]						).groups()[0]
					return ""
def 					_snake_case	(  __snake_case						):
					_UpperCamelCase			     =     len(get_indent(__snake_case						)						) > 0
					if has_indent:
										_UpperCamelCase			     =     f"""class Bla:\n{code}"""
					_UpperCamelCase			     =     black.Mode(target_versions={black.TargetVersion.PYaa}  ,     line_length=119  ,     preview=__snake_case						)
					_UpperCamelCase			     =     black.format_str(__snake_case  ,     mode=__snake_case						)
					_UpperCamelCase     ,    _UpperCamelCase			     =     style_docstrings_in_code(__snake_case						)
					return result[len('''class Bla:\n'''						) :] if has_indent else result
def 					_snake_case	(  __snake_case  ,     __snake_case=False						):
					with open(__snake_case  ,     '''r'''  ,     encoding='''utf-8'''  ,     newline='''\n'''						) as f:
										_UpperCamelCase			     =     f.readlines()
					_UpperCamelCase			     =     []
					_UpperCamelCase			     =     0
					# Not a for loop cause `lines` is going to change (if `overwrite=True`).
					while line_index < len(__snake_case						):
										_UpperCamelCase			     =     _re_copy_warning.search(lines[line_index]						)
										if search is None:
															line_index += 1
															continue

										# There is some copied code here, let's retrieve the original.
										_UpperCamelCase     ,    _UpperCamelCase     ,    _UpperCamelCase			     =     search.groups()
										_UpperCamelCase			     =     find_code_in_diffusers(__snake_case						)
										_UpperCamelCase			     =     get_indent(__snake_case						)

										_UpperCamelCase			     =     line_index + 1 if indent == theoretical_indent else line_index + 2
										_UpperCamelCase			     =     theoretical_indent
										_UpperCamelCase			     =     start_index

										# Loop to check the observed code, stop when indentation diminishes or if we see a End copy comment.
										_UpperCamelCase			     =     True
										while line_index < len(__snake_case						) and should_continue:
															line_index += 1
															if line_index >= len(__snake_case						):
																				break
															_UpperCamelCase			     =     lines[line_index]
															_UpperCamelCase			     =     _should_continue(__snake_case  ,     __snake_case						) and re.search(f"""^{indent}# End copy"""  ,     __snake_case						) is None
										# Clean up empty lines at the end (if any).
										while len(lines[line_index - 1]						) <= 1:
															line_index -= 1

										_UpperCamelCase			     =     lines[start_index:line_index]
										_UpperCamelCase			     =     ''''''.join(__snake_case						)

										# Remove any nested `Copied from` comments to avoid circular copies
										_UpperCamelCase			     =     [line for line in theoretical_code.split('''\n'''						) if _re_copy_warning.search(__snake_case						) is None]
										_UpperCamelCase			     =     '''\n'''.join(__snake_case						)

										# Before comparing, use the `replace_pattern` on the original code.
										if len(__snake_case						) > 0:
															_UpperCamelCase			     =     replace_pattern.replace('''with'''  ,     ''''''						).split(''','''						)
															_UpperCamelCase			     =     [_re_replace_pattern.search(__snake_case						) for p in patterns]
															for pattern in patterns:
																				if pattern is None:
																									continue
																				_UpperCamelCase     ,    _UpperCamelCase     ,    _UpperCamelCase			     =     pattern.groups()
																				_UpperCamelCase			     =     re.sub(__snake_case  ,     __snake_case  ,     __snake_case						)
																				if option.strip() == "all-casing":
																									_UpperCamelCase			     =     re.sub(obja.lower()  ,     obja.lower()  ,     __snake_case						)
																									_UpperCamelCase			     =     re.sub(obja.upper()  ,     obja.upper()  ,     __snake_case						)

            # Blackify after replacement. To be able to do that, we need the header (class or function definition)
            # from the previous line
															_UpperCamelCase			     =     blackify(lines[start_index - 1] + theoretical_code						)
															_UpperCamelCase			     =     theoretical_code[len(lines[start_index - 1]						) :]

										# Test for a diff and act accordingly.
										if observed_code != theoretical_code:
															diffs.append([object_name, start_index]						)
															if overwrite:
																				_UpperCamelCase			     =     lines[:start_index] + [theoretical_code] + lines[line_index:]
																				_UpperCamelCase			     =     start_index + 1

					if overwrite and len(__snake_case						) > 0:
										# Warn the user a file has been modified.
										print(f"""Detected changes, rewriting {filename}."""						)
										with open(__snake_case  ,     '''w'''  ,     encoding='''utf-8'''  ,     newline='''\n'''						) as f:
															f.writelines(__snake_case						)
					return diffs
def 					_snake_case	(  __snake_case = False						):
					_UpperCamelCase			     =     glob.glob(os.path.join(__snake_case  ,     '''**/*.py'''						)  ,     recursive=__snake_case						)
					_UpperCamelCase			     =     []
					for filename in all_files:
										_UpperCamelCase			     =     is_copy_consistent(__snake_case  ,     __snake_case						)
										diffs += [f"""- {filename}: copy does not match {d[0]} at line {d[1]}""" for d in new_diffs]
					if not overwrite and len(__snake_case						) > 0:
										_UpperCamelCase			     =     '''\n'''.join(__snake_case						)
										raise Exception(
										    '''Found the following copy inconsistencies:\n'''
										    + diff
										    + '''\nRun `make fix-copies` or `python utils/check_copies.py --fix_and_overwrite` to fix them.'''						)


if __name__ == "__main__":
					_lowerCAmelCase       =		argparse.ArgumentParser()
					parser.add_argument("--fix_and_overwrite", action="store_true", help="Whether to fix inconsistencies.")
					_lowerCAmelCase       =		parser.parse_args()

					check_copies(args.fix_and_overwrite)



"""simple docstring"""





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







class 							SCREAMING_SNAKE_CASE   :






					"""simple docstring"""



					def __init__(			self     :							Union[str, Any]						):
						lowerCAmelCase__      :		List[str]    							=      {}







					def 			__lowerCAmelCase					(			self     :							Optional[Any]  ,lowercase_     :							Optional[Any]  ,lowercase_     :							str  ,lowercase_     :							List[str]=1						):
						if self.graph.get(lowercase_						):
							if self.graph[u].count([w, v]						) == 0:
								self.graph[u].append([w, v]						)
						else:
							lowerCAmelCase__      :		Optional[int]    							=      [[w, v]]
						if not self.graph.get(lowercase_						):
							lowerCAmelCase__      :		Union[str, Any]    							=      []







					def 			__lowerCAmelCase					(			self     :							List[Any]						):
						return list(self.graph						)







					def 			__lowerCAmelCase					(			self     :							Dict  ,lowercase_     :							Tuple  ,lowercase_     :							Tuple						):
						if self.graph.get(lowercase_						):
							for _ in self.graph[u]:
								if _[1] == v:
									self.graph[u].remove(lowercase_						)







					def 			__lowerCAmelCase					(			self     :							int  ,lowercase_     :							Any=-2  ,lowercase_     :							List[Any]=-1						):
						if s == d:
							return []
						lowerCAmelCase__      :		int    							=      []
						lowerCAmelCase__      :		List[Any]    							=      []
						if s == -2:
							lowerCAmelCase__      :		int    							=      list(self.graph						)[0]
						stack.append(lowercase_						)
						visited.append(lowercase_						)
						lowerCAmelCase__      :		int    							=      s

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

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

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







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







					def 			__lowerCAmelCase					(			self     :							Optional[Any]  ,lowercase_     :							Union[str, Any]=-2						):
						lowerCAmelCase__      :		Tuple    							=      deque()
						lowerCAmelCase__      :		Tuple    							=      []
						if s == -2:
							lowerCAmelCase__      :		Any    							=      list(self.graph						)[0]
						d.append(lowercase_						)
						visited.append(lowercase_						)
						while d:
							lowerCAmelCase__      :		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 			__lowerCAmelCase					(			self     :							Union[str, Any]  ,lowercase_     :							Optional[Any]						):
						lowerCAmelCase__      :		Optional[Any]    							=      0
						for x in self.graph:
							for y in self.graph[x]:
								if y[1] == u:
									count += 1
						return count







					def 			__lowerCAmelCase					(			self     :							str  ,lowercase_     :							Optional[int]						):
						return len(self.graph[u]						)







					def 			__lowerCAmelCase					(			self     :							List[str]  ,lowercase_     :							List[str]=-2						):
						lowerCAmelCase__      :		Union[str, Any]    							=      []
						lowerCAmelCase__      :		Any    							=      []
						if s == -2:
							lowerCAmelCase__      :		Any    							=      list(self.graph						)[0]
						stack.append(lowercase_						)
						visited.append(lowercase_						)
						lowerCAmelCase__      :		Tuple    							=      s
						lowerCAmelCase__      :		Optional[int]    							=      []

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

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

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







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

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

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

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







					def 			__lowerCAmelCase					(			self     :							int						):
						lowerCAmelCase__      :		Tuple    							=      []
						lowerCAmelCase__      :		Tuple    							=      []
						lowerCAmelCase__      :		Any    							=      list(self.graph						)[0]
						stack.append(lowercase_						)
						visited.append(lowercase_						)
						lowerCAmelCase__      :		List[str]    							=      -2
						lowerCAmelCase__      :		int    							=      []
						lowerCAmelCase__      :		int    							=      s
						lowerCAmelCase__      :		List[Any]    							=      False
						lowerCAmelCase__      :		List[str]    							=      set()

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

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

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







					def 			__lowerCAmelCase					(			self     :							Any  ,lowercase_     :							List[Any]=-2  ,lowercase_     :							Union[str, Any]=-1						):
						lowerCAmelCase__      :		Optional[int]    							=      time()
						self.dfs(lowercase_  ,lowercase_						)
						lowerCAmelCase__      :		Any    							=      time()
						return end - begin







					def 			__lowerCAmelCase					(			self     :							Any  ,lowercase_     :							Dict=-2						):
						lowerCAmelCase__      :		List[str]    							=      time()
						self.bfs(lowercase_						)
						lowerCAmelCase__      :		List[Any]    							=      time()
						return end - begin







class 							SCREAMING_SNAKE_CASE   :






					"""simple docstring"""



					def __init__(			self     :							Union[str, Any]						):
						lowerCAmelCase__      :		Tuple    							=      {}







					def 			__lowerCAmelCase					(			self     :							List[Any]  ,lowercase_     :							Optional[int]  ,lowercase_     :							Dict  ,lowercase_     :							Any=1						):
						# check if the u exists
						if self.graph.get(lowercase_						):
							# 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
							lowerCAmelCase__      :		List[Any]    							=      [[w, v]]
						# add the other way
						if self.graph.get(lowercase_						):
							# 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
							lowerCAmelCase__      :		int    							=      [[w, u]]







					def 			__lowerCAmelCase					(			self     :							Dict  ,lowercase_     :							Union[str, Any]  ,lowercase_     :							Dict						):
						if self.graph.get(lowercase_						):
							for _ in self.graph[u]:
								if _[1] == v:
									self.graph[u].remove(lowercase_						)
        # the other way round
						if self.graph.get(lowercase_						):
							for _ in self.graph[v]:
								if _[1] == u:
									self.graph[v].remove(lowercase_						)







					def 			__lowerCAmelCase					(			self     :							int  ,lowercase_     :							Optional[int]=-2  ,lowercase_     :							str=-1						):
						if s == d:
							return []
						lowerCAmelCase__      :		Optional[Any]    							=      []
						lowerCAmelCase__      :		Any    							=      []
						if s == -2:
							lowerCAmelCase__      :		Tuple    							=      list(self.graph						)[0]
						stack.append(lowercase_						)
						visited.append(lowercase_						)
						lowerCAmelCase__      :		int    							=      s

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

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

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







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







					def 			__lowerCAmelCase					(			self     :							Optional[Any]  ,lowercase_     :							List[Any]=-2						):
						lowerCAmelCase__      :		Tuple    							=      deque()
						lowerCAmelCase__      :		List[Any]    							=      []
						if s == -2:
							lowerCAmelCase__      :		Tuple    							=      list(self.graph						)[0]
						d.append(lowercase_						)
						visited.append(lowercase_						)
						while d:
							lowerCAmelCase__      :		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 			__lowerCAmelCase					(			self     :							Any  ,lowercase_     :							Any						):
						return len(self.graph[u]						)







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

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

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

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







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

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

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

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







					def 			__lowerCAmelCase					(			self     :							str						):
						return list(self.graph						)







					def 			__lowerCAmelCase					(			self     :							Any  ,lowercase_     :							Optional[int]=-2  ,lowercase_     :							Any=-1						):
						lowerCAmelCase__      :		Dict    							=      time()
						self.dfs(lowercase_  ,lowercase_						)
						lowerCAmelCase__      :		List[str]    							=      time()
						return end - begin







					def 			__lowerCAmelCase					(			self     :							Union[str, Any]  ,lowercase_     :							int=-2						):
						lowerCAmelCase__      :		Dict    							=      time()
						self.bfs(lowercase_						)
						lowerCAmelCase__      :		Any    							=      time()
						return end - begin




