On the genealogy of branching random walks and of directed polymers