def dyads_stats(edges, n_nodes, root_idx):
    """
    Compute the number of nodes that have 1-way, 2-way and no edges.
    Takes O(|edges|).
    
    NB: you need to know the num of nodes as there might be 0-degree nodes
    
    Input:
        - edges: set of (i, j) tuples
        - n_nodes: number nodes in the graph
        - root_idx: index of the root node
            if None => ignore the root
    """
    n_1way_edges = 0
    n_2way_edges_x2 = 0

    for u, v in edges:
        if root_idx is not None and u == root_idx or v == root_idx:
            continue

        if (v, u) in edges:
            n_2way_edges_x2 += 1
        else:
            n_1way_edges += 1
    
    n_pairs = int(n_nodes * (n_nodes - 1) / 2)
    n_2way_edges = int(n_2way_edges_x2 / 2)
    n_no_edges = n_pairs - (n_1way_edges + n_2way_edges)

    out = {
        "0": n_no_edges,
        "1": n_1way_edges,
        "2": n_2way_edges
    }
    
    return out