Code:
create table class (
teacher_id int,
subject_id int,
foreign key (teacher_id, subject_id) references teacher_subject,
room_id references classroom,
time_slot_id reference time_slot,
unique(teacher_id, time_slot_id),
unique(room_id, time_slot_id)
)
Leave the subject out of your constraint. Whether or not different subjects are being taught, neither teachers nor rooms can be double-booked.