Aberdeen batter basement dwellers Livingston to end their run of six Scottish Premiership games without a win in a topsy-turvy game at Pittodrie that ends with both sides down to 10 men.