Inverness Caley ended their run of six games without success with a 3-2 victory over Hearts at Tynecastle.