#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 of pairs of students will whisper during class.
Students sit in rows and columns. The student in row and column sits at position . To make it easier for students to enter and exit, there are horizontal aisles and 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 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 lines each contain space-separated integers. On the -th line, the integers indicate that the two students at positions and 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 integers , indicating that aisles are to be placed between row and row , between row and row , …, and between row and row , where . Integers are separated by single spaces, with no trailing space.
The second line contains integers , indicating that aisles are to be placed between column and column , between column and column , …, and between column and column , where . 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 pairs of students who will whisper. The bold lines indicate aisles. The shown aisle arrangement is the unique optimal solution.
2008 Junior, problem 2.
Translated by ChatGPT 5
京公网安备 11011102002149号