def set_find(set_nodes, i):
  """
  Set find implementation with path compression

  :param set_nodes: dictionary where key is node id and value is set containing node
  :param i: id of node

  Returns
  -------
  id of the set containing the node i
  """
  if i != set_nodes[i]:
    set_nodes[i] = set_find(set_nodes, set_nodes[i])
  return set_nodes[i]