Statistical mechanics approach to top eigenpairs of sparse symmetric random matrices