MacArthur proceeded to the Yalu with the thought that there was no more organized resistance and that the PRC would not intervene. Thus, the troops going north were not prepared for real, prolonged combat with a strong enemy.
If the US gave real consideration that the PRC would intervene, then the drive to the Yalu would be very different. It means there is no sudden surprise that overwhelms the front lines, and that defensive lines could be formed north of the 38th parallel. UN troops might inflict horrendous casaulties in such a scenario, and might even be able to counter attack and regain some lost ground. I don't know if they could reach the Yalu, but it's at least a possibility.
At that point, negotiations would begin. I don't know if Mao or Stalin would consider a rump North Korean state viable or desirable, and they might be convinced to allow a united Korea provided certain things happened. Perhaps no-US troops after the war, and a neutral Korean state not allied to the US, like in Austria.
The problem lies with MacArthur and his ego.