Sums and products along sparse graphs