


import itertools
from dataclasses import dataclass
from typing import Optional

import pandas as pd
import pyarrow as pa

import datasets
from datasets.table import table_cast


@dataclass
class 					lowerCAmelCase_ (       datasets.BuilderConfig):
						lowerCamelCase_         =     None






class 					lowerCAmelCase_ (       datasets.ArrowBasedBuilder):
						lowerCamelCase_         =     PandasConfig




						def  _snake_case					(	self						:   Tuple						)      ->str:






									"""simple docstring"""






									return datasets.DatasetInfo(features=self.config.features						)




						def  _snake_case					(	self						:   List[str]   ,     __A						:   List[str]						)      ->Union[str, Any]:






									"""simple docstring"""






									if not self.config.data_files:
												raise ValueError(F'''At least one data file must be specified, but got data_files={self.config.data_files}'''						)
									a__ :int						  =    dl_manager.download_and_extract(self.config.data_files						)
									if isinstance(UpperCAmelCase__   ,     (str, list, tuple)						):
												a__ :Any						  =    data_files
												if isinstance(UpperCAmelCase__   ,     UpperCAmelCase__						):
															a__ :Optional[Any]						  =    [files]
												# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
												a__ :Any						  =    [dl_manager.iter_files(UpperCAmelCase__						) for file in files]
												return [datasets.SplitGenerator(name=datasets.Split.TRAIN   ,     gen_kwargs={"files": files}						)]
									a__ :Tuple						  =    []
									for split_name, files in data_files.items():
												if isinstance(UpperCAmelCase__   ,     UpperCAmelCase__						):
															a__ :Dict						  =    [files]
												# Use `dl_manager.iter_files` to skip hidden files in an extracted archive
												a__ :Any						  =    [dl_manager.iter_files(UpperCAmelCase__						) for file in files]
												splits.append(datasets.SplitGenerator(name=UpperCAmelCase__   ,     gen_kwargs={"files": files}						)						)
									return splits




						def  _snake_case					(	self						:   Tuple   ,     __A						:   pa.Table						)      ->pa.Table:






									"""simple docstring"""






									if self.config.features is not None:
												# more expensive cast to support nested features with keys in a different order
												# allows str <-> int/float or str to Audio for example
												a__ :Tuple						  =    table_cast(UpperCAmelCase__   ,     self.config.features.arrow_schema						)
									return pa_table






						def  _snake_case					(	self						:   List[Any]   ,     __A						:   Optional[Any]						)      ->List[Any]:






									"""simple docstring"""






									for i, file in enumerate(itertools.chain.from_iterable(UpperCAmelCase__						)						):
												with open(UpperCAmelCase__   ,     "rb"						) as f:
															a__ :Tuple						  =    pa.Table.from_pandas(pd.read_pickle(UpperCAmelCase__						)						)
															yield i, self._cast_table(UpperCAmelCase__						)






class 					lowerCAmelCase_ :




						def __init__(	self						:   Optional[int]						)      ->Optional[Any]:






									"""simple docstring"""






									a__ :Tuple						  =    {}




						def  _snake_case					(	self						:   Tuple						)      ->None:






									"""simple docstring"""






									print(self.vertex						)
									for i in self.vertex:
												print(__A   ,     " -> "   ,     " -> ".join([str(__A						) for j in self.vertex[i]]						)						)




						def  _snake_case					(	self						:   Optional[int]   ,     __A						:   int   ,     __A						:   int						)      ->None:






									"""simple docstring"""






									if from_vertex in self.vertex:
												self.vertex[from_vertex].append(__A						)
									else:
												# else make a new vertex
												a__ :Any						  =    [to_vertex]




						def  _snake_case					(	self						:   Optional[int]						)      ->None:






									"""simple docstring"""






									a__ :List[Any]						  =    [False] * len(self.vertex						)

									# call the recursive helper function
									for i in range(len(self.vertex						)						):
												if not visited[i]:
															self.dfs_recursive(__A   ,     __A						)






						def  _snake_case					(	self						:   Union[str, Any]   ,     __A						:   int   ,     __A						:   list						)      ->None:






									"""simple docstring"""






									a__ :Dict						  =    True

									print(__A   ,     end=" "						)

									# Recur for all the vertices that are adjacent to this node
									for i in self.vertex:
												if not visited[i]:
															self.dfs_recursive(__A   ,     __A						)


if __name__ == "__main__":
		snake_case__			 =						Graph()
		g.add_edge(0, 1)
		g.add_edge(0, 2)
		g.add_edge(1, 2)
		g.add_edge(2, 0)
		g.add_edge(2, 3)
		g.add_edge(3, 3)

		g.print_graph()
		print('''DFS:''')
		g.dfs()

		# OUTPUT:
		# 0  ->  1 -> 2
		# 1  ->  2
		# 2  ->  0 -> 3
		# 3  ->  3
		# DFS:
		#  0 1 2 3


