

from bisect import bisect
from itertools import accumulate




def 			UpperCAmelCase__				(			_A      : Optional[Any]	,      _A      : Dict	,      _A      : Optional[int]	,      _A      : Tuple							):





  '''simple docstring'''







  a__  =sorted(zip(_A	,      _A							)	,      key=lambda _A							: x[0] / x[1]	,      reverse=_A							)
  a__,      a__  =[i[0] for i in r], [i[1] for i in r]
  a__  =list(accumulate(_A							)							)
  a__  =bisect(_A	,      _A							)
  return (
      0
      if k == 0
      else sum(vl[:k]							) + (w - acc[k - 1]) * (vl[k]) / (wt[k])
      if k != n
      else sum(vl[:k]							)
  )


if __name__ == "__main__":
       import doctest

       doctest.testmod()



def 			UpperCAmelCase__				(			_A      : dict							):





  '''simple docstring'''







  a__  =set()
  # To detect a back edge, keep track of vertices currently in the recursion stack
  a__  =set()
  return any(
      node not in visited and depth_first_search(_A	,      _A	,      _A	,      _A							)
      for node in graph							)




def 			UpperCAmelCase__				(			_A      : dict	,      _A      : int	,      _A      : set	,      _A      : set							):





  '''simple docstring'''







  visited.add(_A							)
  rec_stk.add(_A							)

  for node in graph[vertex]:
    if node not in visited:
      if depth_first_search(_A	,      _A	,      _A	,      _A							):
        return True
    elif node in rec_stk:
      return True

    # The node needs to be removed from recursion stack before function ends
  rec_stk.remove(_A							)
  return False


if __name__ == "__main__":
       from doctest import testmod

       testmod()
