def align_part(bgraph, matching):
    """
    Align edges in matching so that first vertex of each matching edge
    is with attribute bipartite=0.
    """
    aligned = set()
    for edge in matching:
        if bgraph.node[edge[0]]['bipartite'] == 0:
            aligned.add(edge)
        else:
            aligned.add(edge[::-1])
    return aligned
