The underlying space of a scheme remembers its affineness? Let $f:X\rightarrow Y$ be a morphism of schemes. We know that if $Y$ is affine and $f$ induces homeomorphism on the underlying spaces then $X$ is affine. Is it true that if $X$ is affine and $f$ induces a homeomorphism on the underlying spaces then $Y$ is affine? 
More generally, is it true that a scheme whose underlying space is homeomorphic (possibly via a homeomorphism that is not induced by a morphism of schemes) to the underlying space of an affine scheme is affine? EDIT: actually, the answer to the last question is a very strong "NO" as the underlying space of any scheme is sober and Noetherian sober spaces are spectral (i.e. homeomorphic to the underlying space of an affine scheme).   
 A: As pointed out by abx here, the following example fits the bill.
Take a nodal cubic in $\mathbb{P}^2$, this is an irreducible scheme proper over $\mathbb{C}$, take its normalization and throw out a point from the inverse image of the node. We get a $\mathbb{C}$-morphism from the affine line to our cubic, which is bijective on the underlying spaces. Since a non-empty proper closed subspace of either the affine line or the cubic is a finite union of closed points, this morphism is also closed, thus it induces a homeomorphism on the underlying spaces. I find it somewhat amusing that this example was not pointed out earlier (indeed, it seems to be even simpler than Julian Rosen's much upvoted example).
A: Here is a counterexample. Fix a field $k$, and let $Y$ be built from two copies of the affine nodal curve $y^2=x^3+x^2$, glued together on the complement of the singular point. In other words $Y$ is a nodal curve with doubled singular point. Then $Y$ is not affine because it is not separated. However, there is a homeomorphism $\mathbb{A}^1\to Y$, which is built from the usual parameterization of the nodal curve by $\mathbb{A}^1$ (which passes through the singular point twice) by choosing one of version of the singular point the first time through and the other version the second time through.
