An additivity theorem for the genus of a graph