#P1056. [NOIP 2008 普及组] 排座椅

[NOIP 2008 普及组] 排座椅

Description

During class, some students always whisper with the people in front, behind, to the left, or to the right of them. This is very troubling for the primary school homeroom teacher. However, the teacher Xiaoxue noticed something interesting: once the seating positions are fixed, only a limited number DD of pairs of students will whisper during class.

Students sit in MM rows and NN columns. The student in row ii and column jj sits at position (i,j)(i, j). To make it easier for students to enter and exit, there are KK horizontal aisles and LL vertical aisles in the classroom.

Clever Xiaoxue came up with an idea that might reduce whispering: she plans to rearrange the desks and chairs by changing the positions of the aisles. If an aisle separates two students who would whisper, they will stop whispering.

Please help Xiaoxue write a program to output the best aisle placement. Under this plan, the number of whispering pairs during class is minimized.

Input Format

The first line contains 55 space-separated integers: $M,N,K,L,D(2 \le N,M \le 1000,0 \le K<M,0 \le L<N,0\le D \le 2000)$.

The next DD lines each contain 44 space-separated integers. On the ii-th line, the 44 integers Xi,Yi,Pi,QiX_i,Y_i,P_i,Q_i indicate that the two students at positions (Xi,Yi)(X_i,Y_i) and (Pi,Qi)(P_i,Q_i) will whisper (the input guarantees they are adjacent either front/back or left/right).

The input guarantees that the optimal solution is unique.

Output Format

Output two lines. The first line contains KK integers a1,a2,,aKa_1,a_2,\ldots,a_K, indicating that aisles are to be placed between row a1a_1 and row a1+1a_1+1, between row a2a_2 and row a2+1a_2+1, …, and between row aKa_K and row aK+1a_K+1, where ai<ai+1a_i< a_{i+1}. Integers are separated by single spaces, with no trailing space.

The second line contains LL integers b1,b2,,bLb_1,b_2,\ldots,b_L, indicating that aisles are to be placed between column b1b_1 and column b1+1b_1+1, between column b2b_2 and column b2+1b_2+1, …, and between column bLb_L and column bL+1b_L+1, where bi<bi+1b_i< b_{i+1}. Integers are separated by single spaces, with no trailing space.

4 5 1 2 3
4 2 4 3
2 3 3 3
2 5 2 4

2
2 4

Hint

In the figure, the symbols *, ※, and + mark 33 pairs of students who will whisper. The 33 bold lines indicate aisles. The shown aisle arrangement is the unique optimal solution.

2008 Junior, problem 2.

Translated by ChatGPT 5