The genetic mechanism of selfishness and altruism in parent-offspring coadaptation