Interaction of a cosmological gamma-ray burst with a dense molecular cloud and the formation of jets