That’s why it’s important to make exercise a lifelong habit. Diet to lose the weight, exercise to keep it off.
To some extent you always need to manage your caloric intake of course - but if you exercise regularly, the occasional indulgence isn’t a big deal.