Here qi=CV and qf=2CV
As battery is connected with opposite polarity so charge flow through the battery is Δq=qf−(−qi)=2CV+CV=3CV.
Initial energy stored ,Ui=12CV2 and
Final energy stored , Uf=12C(2V)2=2CV2.
Generated heat, H=(Uf−Ui)−Δq(2V)=2CV2−12CV2−6CV2=−92CV2
Thus,HUf=9CV22(2CV2)=2.25