import collections


def simplified_hth_graph(G):
  """
  Creates a simplified head-to-head graph.

  G attribute should be a normal head-to-head graph.

  The simplified graph has no more than a single edge between
  two nodes. Technically if the two nodes are in a draw relation
  then there are two win edges between them vica versa.

  The remained edges reflect the dominance relations of the node
  pairs.
  """
  H = G.__class__()
  H.add_nodes_from(G)
  C = collections.Counter(e[:2] for e in G.edges)
      # edge key ignored hence e[:2]
  while True:  # simplify multi edges
    count = 0
    for (name1, name2), count in C.most_common():
      if count <= 1:
        break
      reverse_count = C[(name2, name1)]  # reverse_count < count
      if reverse_count < count:
        H.add_edge(name1, name2)
      elif reverse_count == count:
        H.add_edge(name1, name2)
        H.add_edge(name2, name1)
      else:  # should never reached because of C.most_common()
        raise NotImplementedError("unexpected count relation")
      del C[(name1, name2)]
      del C[(name2, name1)]
    if count <= 1:
      break
  for (name1, name2) in C:  # add the remaining single edges
    H.add_edge(name1, name2)
  return H