How did nationalism contribute to the spread of imperialism during the nineteenth and early twentieth centuries?