The branching random walk and contact process on Galton-Watson and nonhomogeneous trees