If you had come in time, you wouldn't have missed the train.

Hi!

I am wondering about the legitimacy of the phrase written above. Is it correct?
If so, why does the first part contain had while the second contains have?

I hope for help in English and Russian.

Thank you!