Given proposed FC and IC lab slots with teacher conflicts, seat limits, and timing rules, choose a valid set of labs using the fewest distinct starting days.
Hard9GraphBFSGreedyImplementationNo attempts yetTime limit2sMemory limit512 MBMajestic Gourmet University awards the Majestic International Cooking Degree to a large number of students every year.
Every student takes two mandatory classes, French Cuisine (FC) and Italian Cuisine (IC). Two disjoint groups of teachers run them, the FC teachers and the IC teachers. Both classes run as weekly cooking labs and have a limited number of seats, KFC students per FC lab and KIC students per IC lab. Several lab instances of each class therefore run every week, and each instance has its own weekly timeslot and its own assigned teacher. One more complication exists. Some of the teachers are in open conflict with each other because they disagree on teaching methods.
Every year the heads of the FC department and the IC department propose a number of weekly lab instances, and Bob from the Planning Office picks a subset of these propositions so that every student gets a valid timetable, which means:
Timeslots are compared over the whole week. A lab that starts on day d at h hours m minutes runs from minute 1440(d−1)+60h+m to minute 1440(d−1)+60h+m+60L, where L is the duration of that class in hours. A student can attend two labs exactly when one of them starts at least 5 minutes after the other one ends.
Some teachers may take no lab instance at all, and one teacher may be in charge of several labs.
Help Bob and report the smallest possible number of days.
Every line holds integers separated by single spaces.
The first line holds S, the number of registered students.
The second line holds NFC, KFC, DFC and TFC: the number of FC lab propositions, the seat limit of every FC lab, the duration in hours of every FC lab, and the number of FC teachers.
Each of the next NFC lines describes one proposed FC lab slot with four integers d, h, m and t: the day of the week, the starting hour, the starting minute, and the FC teacher in charge.
The next line holds NIC, KIC, DIC and TIC with the same meanings for IC.
Each of the next NIC lines describes one proposed IC lab slot in the same format.
The next line holds C, the number of conflicts among teachers.
Each of the last C lines holds two integers i and j, meaning that FC teacher i is in conflict with IC teacher j.
The limits are:
Two propositions for the same teacher never overlap.
Print one integer on a single line. Print 0 if no valid choice exists. Otherwise print the smallest number of days of the week that carry the starting times of the picked lab slots.