






'''simple docstring'''
import argparse
import json
import os
import sys
import tempfile
import unittest
from argparse import Namespace
from dataclasses import dataclass, field
from enum import Enum
from pathlib import Path
from typing import List, Literal, Optional

import yaml

from transformers import HfArgumentParser, TrainingArguments
from transformers.hf_argparser import make_choice_type_function, string_to_bool


# Since Python 3.10, we can use the builtin `|` operator for Union types
# See PEP 604: https://peps.python.org/pep-0604
UpperCamelCase__ =			sys.version_info >= (3, 10)




def 		__SCREAMING_SNAKE_CASE					(  _UpperCamelCase=None						,		_UpperCamelCase=None							):


   """simple docstring"""




   return field(default_factory=lambda: default						,		metadata=_UpperCamelCase							)


@dataclass
class        _UpperCAmelCase						:
     __lowerCamelCase:   int
     __lowerCamelCase:   float
     __lowerCamelCase:   str
     __lowerCamelCase:   bool


@dataclass
class        _UpperCAmelCase						:
     __lowerCamelCase:   int		       =    42
     __lowerCamelCase:   str		       =    field(default='toto'				,					metadata={'help': 'help message'}			)


@dataclass
class        _UpperCAmelCase						:
     __lowerCamelCase:   bool		       =    False
     __lowerCamelCase:   bool		       =    True
     __lowerCamelCase:   Optional[bool]		       =    None


class        _UpperCAmelCase						(		snake_case			):
     __lowerCamelCase:   List[Any]		       =    'titi'
     __lowerCamelCase:   Optional[Any]		       =    'toto'


class        _UpperCAmelCase						(		snake_case			):
     __lowerCamelCase:   List[Any]		       =    'titi'
     __lowerCamelCase:   List[str]		       =    'toto'
     __lowerCamelCase:   Tuple		       =    42


@dataclass
class        _UpperCAmelCase						:
     __lowerCamelCase:   BasicEnum		       =    "toto"




     def 				lowerCAmelCase__				(			self  :       Any			):






        '''simple docstring'''






        lowercase_	:    List[Any]           =     BasicEnum(self.foo			)


@dataclass
class        _UpperCAmelCase						:
     __lowerCamelCase:   MixedTypeEnum		       =    "toto"




     def 				lowerCAmelCase__				(			self  :       str			):






        '''simple docstring'''






        lowercase_	:    List[str]           =     MixedTypeEnum(self.foo			)


@dataclass
class        _UpperCAmelCase						:
     __lowerCamelCase:   Optional[int]		       =    None
     __lowerCamelCase:   Optional[float]		       =    field(default=snake_case				,					metadata={'help': 'help message'}			)
     __lowerCamelCase:   Optional[str]		       =    None
     __lowerCamelCase:   Optional[List[str]]		       =    list_field(default=[]			)
     __lowerCamelCase:   Optional[List[int]]		       =    list_field(default=[]			)


@dataclass
class        _UpperCAmelCase						:
     __lowerCamelCase:   List[int]		       =    list_field(default=[]			)
     __lowerCamelCase:   List[int]		       =    list_field(default=[1, 2, 3]			)
     __lowerCamelCase:   List[str]		       =    list_field(default=['Hallo', 'Bonjour', 'Hello']			)
     __lowerCamelCase:   List[float]		       =    list_field(default=[0.1, 0.2, 0.3]			)


@dataclass
class        _UpperCAmelCase						:
     __lowerCamelCase:   List[int]		       =    field()
     __lowerCamelCase:   str		       =    field()
     __lowerCamelCase:   BasicEnum		       =    field()




     def 				lowerCAmelCase__				(			self  :       List[str]			):






        '''simple docstring'''






        lowercase_	:    List[Any]           =     BasicEnum(self.required_enum			)


@dataclass
class        _UpperCAmelCase						:
     __lowerCamelCase:   int
     __lowerCamelCase:   "BasicEnum"		       =    field()
     __lowerCamelCase:   "Optional[bool]"		       =    None
     __lowerCamelCase:   "str"		       =    field(default='toto'				,					metadata={'help': 'help message'}			)
     __lowerCamelCase:   "List[str]"		       =    list_field(default=['Hallo', 'Bonjour', 'Hello']			)


if is_python_no_less_than_3_10:


 @dataclass
 class        _UpperCAmelCase						:
      __lowerCamelCase:   bool		       =    False
      __lowerCamelCase:   bool		       =    True
      __lowerCamelCase:   bool | None		       =    None


 @dataclass
 class        _UpperCAmelCase						:
      __lowerCamelCase:   int | None		       =    None
      __lowerCamelCase:   float | None		       =    field(default=snake_case				,					metadata={'help': 'help message'}			)
      __lowerCamelCase:   str | None		       =    None
      __lowerCamelCase:   list[str] | None		       =    list_field(default=[]			)
      __lowerCamelCase:   list[int] | None		       =    list_field(default=[]			)





class        _UpperCAmelCase						(		unittest.TestCase			):




     def 				lowerCAmelCase__				(			self  :       Any  ,     a  :       argparse.ArgumentParser  ,     a  :       argparse.ArgumentParser			):






        '''simple docstring'''






        self.assertEqual(len(a._actions			)  ,     len(b._actions			)			)
        for x, y in zip(a._actions  ,     b._actions			):
           lowercase_	:    str           =     {k: v for k, v in vars(a			).items() if k != "container"}
           lowercase_	:    List[Any]           =     {k: v for k, v in vars(a			).items() if k != "container"}

           # Choices with mixed type have custom function as "type"
           # So we need to compare results directly for equality
           if xx.get("choices"  ,     a			) and yy.get("choices"  ,     a			):
              for expected_choice in yy["choices"] + xx["choices"]:
                 self.assertEqual(xx["type"](a			)  ,     yy["type"](a			)			)
              del xx["type"], yy["type"]

           self.assertEqual(a  ,     a			)




     def 				lowerCAmelCase__				(			self  :       List[str]			):






        '''simple docstring'''






        lowercase_	:    str           =     HfArgumentParser(a			)

        lowercase_	:    Any           =     argparse.ArgumentParser()
        expected.add_argument("--foo"  ,     type=a  ,     required=a			)
        expected.add_argument("--bar"  ,     type=a  ,     required=a			)
        expected.add_argument("--baz"  ,     type=a  ,     required=a			)
        expected.add_argument("--flag"  ,     type=a  ,     default=a  ,     const=a  ,     nargs="?"			)
        self.argparsersEqual(a  ,     a			)

        lowercase_	:    Tuple           =     ["--foo", "1", "--baz", "quux", "--bar", "0.5"]
        (lowercase_		)	:    List[str]           =     parser.parse_args_into_dataclasses(a  ,     look_for_args_file=a			)
        self.assertFalse(example.flag			)




     def 				lowerCAmelCase__				(			self  :       Optional[Any]			):






        '''simple docstring'''






        lowercase_	:    int           =     HfArgumentParser(a			)

        lowercase_	:    Optional[int]           =     argparse.ArgumentParser()
        expected.add_argument("--foo"  ,     default=4_2  ,     type=a			)
        expected.add_argument("--baz"  ,     default="toto"  ,     type=a  ,     help="help message"			)
        self.argparsersEqual(a  ,     a			)




     def 				lowerCAmelCase__				(			self  :       List[str]			):






        '''simple docstring'''






        lowercase_	:    Optional[int]           =     argparse.ArgumentParser()
        expected.add_argument("--foo"  ,     type=a  ,     default=a  ,     const=a  ,     nargs="?"			)
        expected.add_argument("--baz"  ,     type=a  ,     default=a  ,     const=a  ,     nargs="?"			)
        # A boolean no_* argument always has to come after its "default: True" regular counter-part
        # and its default must be set to False
        expected.add_argument("--no_baz"  ,     action="store_false"  ,     default=a  ,     dest="baz"			)
        expected.add_argument("--opt"  ,     type=a  ,     default=a			)

        lowercase_	:    str           =     [WithDefaultBoolExample]
        if is_python_no_less_than_3_10:
           dataclass_types.append(a			)

        for dataclass_type in dataclass_types:
           lowercase_	:    Tuple           =     HfArgumentParser(a			)
           self.argparsersEqual(a  ,     a			)

           lowercase_	:    str           =     parser.parse_args([]			)
           self.assertEqual(a  ,     Namespace(foo=a  ,     baz=a  ,     opt=a			)			)

           lowercase_	:    Union[str, Any]           =     parser.parse_args(["--foo", "--no_baz"]			)
           self.assertEqual(a  ,     Namespace(foo=a  ,     baz=a  ,     opt=a			)			)

           lowercase_	:    Tuple           =     parser.parse_args(["--foo", "--baz"]			)
           self.assertEqual(a  ,     Namespace(foo=a  ,     baz=a  ,     opt=a			)			)

           lowercase_	:    Dict           =     parser.parse_args(["--foo", "True", "--baz", "True", "--opt", "True"]			)
           self.assertEqual(a  ,     Namespace(foo=a  ,     baz=a  ,     opt=a			)			)

           lowercase_	:    Tuple           =     parser.parse_args(["--foo", "False", "--baz", "False", "--opt", "False"]			)
           self.assertEqual(a  ,     Namespace(foo=a  ,     baz=a  ,     opt=a			)			)




     def 				lowerCAmelCase__				(			self  :       Union[str, Any]			):






        '''simple docstring'''






        lowercase_	:    List[Any]           =     HfArgumentParser(a			)

        lowercase_	:    str           =     argparse.ArgumentParser()
        expected.add_argument(
            "--foo"  ,     default="toto"  ,     choices=["titi", "toto", 4_2]  ,     type=make_choice_type_function(["titi", "toto", 4_2]			)  ,     )
        self.argparsersEqual(a  ,     a			)

        lowercase_	:    List[Any]           =     parser.parse_args([]			)
        self.assertEqual(args.foo  ,     "toto"			)
        lowercase_	:    Union[str, Any]           =     parser.parse_args_into_dataclasses([]			)[0]
        self.assertEqual(enum_ex.foo  ,     MixedTypeEnum.toto			)

        lowercase_	:    Tuple           =     parser.parse_args(["--foo", "titi"]			)
        self.assertEqual(args.foo  ,     "titi"			)
        lowercase_	:    Any           =     parser.parse_args_into_dataclasses(["--foo", "titi"]			)[0]
        self.assertEqual(enum_ex.foo  ,     MixedTypeEnum.titi			)

        lowercase_	:    Any           =     parser.parse_args(["--foo", "42"]			)
        self.assertEqual(args.foo  ,     4_2			)
        lowercase_	:    str           =     parser.parse_args_into_dataclasses(["--foo", "42"]			)[0]
        self.assertEqual(enum_ex.foo  ,     MixedTypeEnum.fourtytwo			)




     def 				lowerCAmelCase__				(			self  :       List[Any]			):






        '''simple docstring'''






        @dataclass
        class        _UpperCAmelCase						:
             __lowerCamelCase:   Literal["titi", "toto", 42]		       =    "toto"


        lowercase_	:    int           =     HfArgumentParser(a			)

        lowercase_	:    List[Any]           =     argparse.ArgumentParser()
        expected.add_argument(
            "--foo"  ,     default="toto"  ,     choices=("titi", "toto", 4_2)  ,     type=make_choice_type_function(["titi", "toto", 4_2]			)  ,     )
        self.argparsersEqual(a  ,     a			)

        lowercase_	:    Any           =     parser.parse_args([]			)
        self.assertEqual(args.foo  ,     "toto"			)

        lowercase_	:    List[Any]           =     parser.parse_args(["--foo", "titi"]			)
        self.assertEqual(args.foo  ,     "titi"			)

        lowercase_	:    str           =     parser.parse_args(["--foo", "42"]			)
        self.assertEqual(args.foo  ,     4_2			)




     def 				lowerCAmelCase__				(			self  :       List[str]			):






        '''simple docstring'''






        lowercase_	:    List[Any]           =     HfArgumentParser(a			)

        lowercase_	:    List[str]           =     argparse.ArgumentParser()
        expected.add_argument("--foo_int"  ,     nargs="+"  ,     default=[]  ,     type=a			)
        expected.add_argument("--bar_int"  ,     nargs="+"  ,     default=[1, 2, 3]  ,     type=a			)
        expected.add_argument("--foo_str"  ,     nargs="+"  ,     default=["Hallo", "Bonjour", "Hello"]  ,     type=a			)
        expected.add_argument("--foo_float"  ,     nargs="+"  ,     default=[0.1, 0.2, 0.3]  ,     type=a			)

        self.argparsersEqual(a  ,     a			)

        lowercase_	:    Dict           =     parser.parse_args([]			)
        self.assertEqual(
            a  ,     Namespace(foo_int=[]  ,     bar_int=[1, 2, 3]  ,     foo_str=["Hallo", "Bonjour", "Hello"]  ,     foo_float=[0.1, 0.2, 0.3]			)  ,     )

        lowercase_	:    Union[str, Any]           =     parser.parse_args("--foo_int 1 --bar_int 2 3 --foo_str a b c --foo_float 0.1 0.7".split()			)
        self.assertEqual(a  ,     Namespace(foo_int=[1]  ,     bar_int=[2, 3]  ,     foo_str=["a", "b", "c"]  ,     foo_float=[0.1, 0.7]			)			)




     def 				lowerCAmelCase__				(			self  :       int			):






        '''simple docstring'''






        lowercase_	:    Optional[Any]           =     argparse.ArgumentParser()
        expected.add_argument("--foo"  ,     default=a  ,     type=a			)
        expected.add_argument("--bar"  ,     default=a  ,     type=a  ,     help="help message"			)
        expected.add_argument("--baz"  ,     default=a  ,     type=a			)
        expected.add_argument("--ces"  ,     nargs="+"  ,     default=[]  ,     type=a			)
        expected.add_argument("--des"  ,     nargs="+"  ,     default=[]  ,     type=a			)

        lowercase_	:    int           =     [OptionalExample]
        if is_python_no_less_than_3_10:
           dataclass_types.append(a			)

        for dataclass_type in dataclass_types:
           lowercase_	:    Optional[Any]           =     HfArgumentParser(a			)

           self.argparsersEqual(a  ,     a			)

           lowercase_	:    Any           =     parser.parse_args([]			)
           self.assertEqual(a  ,     Namespace(foo=a  ,     bar=a  ,     baz=a  ,     ces=[]  ,     des=[]			)			)

           lowercase_	:    Optional[int]           =     parser.parse_args("--foo 12 --bar 3.14 --baz 42 --ces a b c --des 1 2 3".split()			)
           self.assertEqual(a  ,     Namespace(foo=1_2  ,     bar=3.14  ,     baz="42"  ,     ces=["a", "b", "c"]  ,     des=[1, 2, 3]			)			)




     def 				lowerCAmelCase__				(			self  :       Optional[int]			):






        '''simple docstring'''






        lowercase_	:    List[str]           =     HfArgumentParser(a			)

        lowercase_	:    Any           =     argparse.ArgumentParser()
        expected.add_argument("--required_list"  ,     nargs="+"  ,     type=a  ,     required=a			)
        expected.add_argument("--required_str"  ,     type=a  ,     required=a			)
        expected.add_argument(
            "--required_enum"  ,     type=make_choice_type_function(["titi", "toto"]			)  ,     choices=["titi", "toto"]  ,     required=a  ,     )
        self.argparsersEqual(a  ,     a			)




     def 				lowerCAmelCase__				(			self  :       int			):






        '''simple docstring'''






        lowercase_	:    str           =     HfArgumentParser(a			)

        lowercase_	:    str           =     argparse.ArgumentParser()
        expected.add_argument("--foo"  ,     type=a  ,     required=a			)
        expected.add_argument(
            "--required_enum"  ,     type=make_choice_type_function(["titi", "toto"]			)  ,     choices=["titi", "toto"]  ,     required=a  ,     )
        expected.add_argument("--opt"  ,     type=a  ,     default=a			)
        expected.add_argument("--baz"  ,     default="toto"  ,     type=a  ,     help="help message"			)
        expected.add_argument("--foo_str"  ,     nargs="+"  ,     default=["Hallo", "Bonjour", "Hello"]  ,     type=a			)
        self.argparsersEqual(a  ,     a			)




     def 				lowerCAmelCase__				(			self  :       List[Any]			):






        '''simple docstring'''






        lowercase_	:    Tuple           =     HfArgumentParser(a			)

        lowercase_	:    Any           =     {
            "foo": 1_2,
            "bar": 3.14,
            "baz": "42",
            "flag": True,
        }

        lowercase_	:    Dict           =     parser.parse_dict(a			)[0]
        lowercase_	:    Optional[Any]           =     BasicExample(**a			)
        self.assertEqual(a  ,     a			)




     def 				lowerCAmelCase__				(			self  :       Tuple			):






        '''simple docstring'''






        lowercase_	:    Dict           =     HfArgumentParser(a			)

        lowercase_	:    Union[str, Any]           =     {
            "foo": 1_2,
            "bar": 3.14,
            "baz": "42",
            "flag": True,
            "extra": 4_2,
        }

        self.assertRaises(a  ,     parser.parse_dict  ,     a  ,     allow_extra_keys=a			)




     def 				lowerCAmelCase__				(			self  :       Any			):






        '''simple docstring'''






        lowercase_	:    Optional[Any]           =     HfArgumentParser(a			)

        lowercase_	:    Optional[Any]           =     {
            "foo": 1_2,
            "bar": 3.14,
            "baz": "42",
            "flag": True,
        }
        with tempfile.TemporaryDirectory() as tmp_dir:
           lowercase_	:    str           =     os.path.join(a  ,     "temp_json"			)
           os.mkdir(a			)
           with open(temp_local_path + ".json"  ,     "w+"			) as f:
              json.dump(a  ,     a			)
           lowercase_	:    int           =     parser.parse_yaml_file(Path(temp_local_path + ".json"			)			)[0]

        lowercase_	:    Union[str, Any]           =     BasicExample(**a			)
        self.assertEqual(a  ,     a			)




     def 				lowerCAmelCase__				(			self  :       List[Any]			):






        '''simple docstring'''






        lowercase_	:    Tuple           =     HfArgumentParser(a			)

        lowercase_	:    Optional[int]           =     {
            "foo": 1_2,
            "bar": 3.14,
            "baz": "42",
            "flag": True,
        }
        with tempfile.TemporaryDirectory() as tmp_dir:
           lowercase_	:    int           =     os.path.join(a  ,     "temp_yaml"			)
           os.mkdir(a			)
           with open(temp_local_path + ".yaml"  ,     "w+"			) as f:
              yaml.dump(a  ,     a			)
           lowercase_	:    Optional[int]           =     parser.parse_yaml_file(Path(temp_local_path + ".yaml"			)			)[0]
        lowercase_	:    List[Any]           =     BasicExample(**a			)
        self.assertEqual(a  ,     a			)





     def 				lowerCAmelCase__				(			self  :       Optional[Any]			):






        '''simple docstring'''






        lowercase_	:    Union[str, Any]           =     HfArgumentParser(a			)
        self.assertIsNotNone(a			)












'''simple docstring'''
import heapq




def 		__SCREAMING_SNAKE_CASE					(  _UpperCamelCase							):


   """simple docstring"""




   lowercase_	:    list[list]           =     []

   # for each node and his adjacency list add them and the rank of the node to queue
   # using heapq module the queue will be filled like a Priority Queue
   # heapq works with a min priority queue, so I used -1*len(v) to build it
   for key, value in graph.items():
      # O(log(n))
      heapq.heappush(_UpperCamelCase						,		[-1 * len(_UpperCamelCase							), (key, value)]							)

   # chosen_vertices = set of chosen vertices
   lowercase_	:    Optional[Any]           =     set()

   # while queue isn't empty and there are still edges
   #   (queue[0][0] is the rank of the node with max rank)
   while queue and queue[0][0] != 0:
      # extract vertex with max rank from queue and add it to chosen_vertices
      lowercase_	:    Any           =     heapq.heappop(_UpperCamelCase							)[1][0]
      chosen_vertices.add(_UpperCamelCase							)

      # Remove all arcs adjacent to argmax
      for elem in queue:
         # if v haven't adjacent node, skip
         if elem[0] == 0:
            continue
         # if argmax is reachable from elem
         # remove argmax from elem's adjacent list and update his rank
         if argmax in elem[1][1]:
            lowercase_	:    str           =     elem[1][1].index(_UpperCamelCase							)
            del elem[1][1][index]
            elem[0] += 1
        # re-order the queue
      heapq.heapify(_UpperCamelCase							)
   return chosen_vertices


if __name__ == "__main__":
 import doctest

 doctest.testmod()

 UpperCamelCase__ =			{0: [1, 3], 1: [0, 3], 2: [0, 3, 4], 3: [0, 1, 2], 4: [2, 3]}
 print(f"""Minimum vertex cover:\n{greedy_min_vertex_cover(graph)}""")




