On the Baumslag-Solitar groups and certain generalized free products