def _add_edge(g, u, v):
    """Add edge to graph or increase edge weight."""
    if g.has_edge(u, v):
        g.edge[u][v]['weight'] += 1
    else:
        g.add_edge(u, v, {'weight': 1})
    return g
