partition and count edges