Is it safe to have anal sex immediately after a vaginal intercourse?

Better than reverse. If it is not causing any pain, and you don't have any vaginal infection, then anal sex after vaginal sex is not likely to be a problem. Go slow, use lots of high quality lube such as pjur or astroglide, be gentle and stop if it hurts! having anal sex before vaginal sex is likely to cause a severe vaginal infection, so don't go back to the vagina until after you have cleaned up with soap and water.