The Kähler-Ricci flow and K-polystability