def add_edge(graph, edge):
    """Adds an edge to a given graph.

  If an edge between the two nodes already exists, the one with the largest
  weight is retained.

  Args:
    graph: A `dict`: source_id -> (target_id -> weight) to be augmented.
    edge: A `list` (or `tuple`) of the form `[source, target, weight]`, where
      `source` and `target` are strings, and `weight` is a numeric value of
      type `string` or `float`. The 'weight' component is optional; if not
      supplied, it defaults to 1.0.

  Returns:
    `None`. Instead, this function has a side-effect on the `graph` argument.
  """
    source = edge[0]
    if source not in graph:
        graph[source] = {}
    t_dict = graph[source]
    target = edge[1]
    weight = float(edge[2]) if len(edge) > 2 else 1.0
    if target not in t_dict or weight > t_dict[target]:
        t_dict[target] = weight
