M.P.
GrammaRocks is right on. I suggest that you're trying to hard and turning this into too big of a deal. Your son will be having similar situations the rest of his life and he'll learn different ways of handling it as he ages.
I suggest that you sympathize with him. Then you ask him what he thinks he can do or what he'd like to do. Tell him he can be friends with both of them. Tell him the situation is difficult but not a big deal. That kids do this all the time and that you know he'll be able to figure it out. Give him the power to manage on his own with your support. You're there to sympathize and for him to bounce ideas off of. But giving him the answer doesn't work because you're not him or the other boys.
Your son is too young to be able to navigate preventing hurt feelings. In reality I think we as a society focus too much on not hurting feelings. I suggest it's reasonable for you son to tell A that he's playing with B now and will play with him later. Truthfulness told kindly always works. If someone takes offense it's their problem. We all have to learn to take care of ourselves and not expect others to pussy foot around us.
I also suggest that you talk with his teacher. She sees them everyday and will have a better idea about what is going on. I suggest that she's already helping them navigate their relationships.