The Ultimatum game, in which one subject proposes how to share a pot and the other has veto power on the proposal, in which case both lose everything, is a paradigmatic scenario to probe the degree of cooperation and altruism in human subjects. It has been shown that if individuals are empathic, i.e., they play the game having in mind how their opponent will react by offering an amount that they themselves would accept, then non-rational large offers well above the smallest possible ones are evolutionarily selected. We here show that empathy itself may be selected and need not be exogenously imposed provided that interactions take place only with a fraction of the total population, and that the role of proposer or responder is randomly changed from round to round. These empathic agents, that displace agents with independent (uncorrelated) offers and proposals, behave far from what is expected rationally, offering and accepting sizable fractions of the amount to be shared. Specific values for the typical offer depend on the details of the interacion network and on the existence of hubs, but they are almost always significantly larger than zero, indicating that the mechanism at work here is quite general and could explain the emergence of empathy in very many different contexts.