Barium and europium abundances in cool dwarf stars and nucleosynthesis of heavy elements