Bỏ qua đến nội dung
Quay lại bài tập

bcadif

Trại đông Bảo Lộc 2021 - Sắp xếp thời khoá biểu

Giới hạn thời gian
1s
Giới hạn bộ nhớ
1024 MB
Điểm
3.5(Chấm điểm từng phần)
Nhóm
Trại đông

Tác giả: @BJMinhNhut

At the beginning of the semester, the head of a computer science department D have to assign courses to teachers in a balanced way. The department DD has mm teachers T={1,2,...,m}T = \{1, 2, ..., m\} and nn courses C={1,2,...,n}C = \{1, 2, ..., n\}. Each teacher t∈Tt ∈ T has a preference list which is a list of courses he/she can teach depending on his/her specialization. We known a list of pairs of conflicting two courses that cannot be assigned to the same teacher as these courses have been already scheduled in the same slot of the timetable. The load of a teacher is the number of courses assigned to her/him. How to assign nn courses to mm teacher such that each course assigned to a teacher is in his/her preference list, no two conflicting courses are assigned to the same teacher, and the maximal load is minimal.

Dữ liệu vào

The input consists of following lines

  • Line 11: contains two integer mm and nn (1≤m≤15,1≤n≤30)(1 ≤ m ≤ 15, 1 ≤ n ≤ 30)
  • Line i+1i+1: contains an positive integer kk and kk positive integers indicating the courses that teacher ii can teach (∀i=1,...,m)(∀i = 1, . . . , m)
  • Line m+2m + 2: contains an integer qq
  • Line i+m+2i + m + 2: contains two integer ii and jj indicating two conflicting courses (∀i=1,...,q)(∀i = 1, . . . , q)

Dữ liệu ra

The output contains a unique number which is the maximal load of the teachers in the solution found and the value −1-1 if no solution found.

Sample Input

4 12
5 1 3 5 10 12
5 9 3 4 8 12
6 1 2 3 4 9 7
7 1 2 3 5 6 10 11
25
1 2
1 3
1 5
2 4
2 5
2 6
3 5
3 7
3 10
4 6
4 9
5 6
5 7
5 8
6 8
6 9
7 8
7 10
7 11
8 9
8 11
8 12
9 12
10 11
11 12

Sample Output

3

Nguồn: Trại đông Bảo Lộc 2021 - thầy Đỗ Phan Thuận