1627: [NOIP2008 普及组] 排座椅

Memory Limit:128 MB Time Limit:1.000 S
Judge Style:Text Compare Creator:
Submit:4 Solved:3

Description

上课的时候总会有一些同学和前后左右的人交头接耳,这是令小学班主任十分头疼的一件事情。不过,班主任小雪发现了一些有趣的现象,当同学们的座次确定下来之后,只有有限的 lns="http://www.w3.org/1998/Math/MathML">D 对同学上课时会交头接耳。

同学们在教室中坐成了 lns="http://www.w3.org/1998/Math/MathML">M 行 lns="http://www.w3.org/1998/Math/MathML">N 列,坐在第 lns="http://www.w3.org/1998/Math/MathML">i 行第 lns="http://www.w3.org/1998/Math/MathML">j 列的同学的位置是 lns="http://www.w3.org/1998/Math/MathML">(i,j),为了方便同学们进出,在教室中设置了 lns="http://www.w3.org/1998/Math/MathML">K 条横向的通道,lns="http://www.w3.org/1998/Math/MathML">L 条纵向的通道。

于是,聪明的小雪想到了一个办法,或许可以减少上课时学生交头接耳的问题:她打算重新摆放桌椅,改变同学们桌椅间通道的位置,因为如果一条通道隔开了 lns="http://www.w3.org/1998/Math/MathML">2 个会交头接耳的同学,那么他们就不会交头接耳了。

请你帮忙给小雪编写一个程序,给出最好的通道划分方案。在该方案下,上课时交头接耳的学生的对数最少。

Input

第一行,有 lns="http://www.w3.org/1998/Math/MathML">5 个用空格隔开的整数,分别是 lns="http://www.w3.org/1998/Math/MathML">M,N,K,L,D(2 \le N,M \le 1000,0 \le K<M,0 \le L<N,D \le 2000)

接下来的 lns="http://www.w3.org/1998/Math/MathML">D 行,每行有 lns="http://www.w3.org/1998/Math/MathML">4 个用空格隔开的整数。第 lns="http://www.w3.org/1998/Math/MathML">i 行的 lns="http://www.w3.org/1998/Math/MathML">4 个整数 lns="http://www.w3.org/1998/Math/MathML">X_i,Y_i,P_i,Q_i,表示坐在位置 lns="http://www.w3.org/1998/Math/MathML">(X_i,Y_i) 与 lns="http://www.w3.org/1998/Math/MathML">(P_i,Q_i) 的两个同学会交头接耳(输入保证他们前后相邻或者左右相邻)。

输入数据保证最优方案的唯一性。

Output

共两行。
第一行包含 lns="http://www.w3.org/1998/Math/MathML">K 个整数 lns="http://www.w3.org/1998/Math/MathML">a_1,a_2,\ldots,a_K,表示第 lns="http://www.w3.org/1998/Math/MathML">a_1 行和 lns="http://www.w3.org/1998/Math/MathML">a_1+1 行之间、第 lns="http://www.w3.org/1998/Math/MathML">a_2 行和 lns="http://www.w3.org/1998/Math/MathML">a_2+1 行之间、…、第 lns="http://www.w3.org/1998/Math/MathML">a_K 行和第 lns="http://www.w3.org/1998/Math/MathML">a_K+1 行之间要开辟通道,其中 lns="http://www.w3.org/1998/Math/MathML">a_i< a_{i+1},每两个整数之间用空格隔开(行尾没有空格)。

第二行包含 lns="http://www.w3.org/1998/Math/MathML">L 个整数 lns="http://www.w3.org/1998/Math/MathML">b_1,b_2,\ldots,b_L,表示第 lns="http://www.w3.org/1998/Math/MathML">b_1 列和 lns="http://www.w3.org/1998/Math/MathML">b_1+1 列之间、第 lns="http://www.w3.org/1998/Math/MathML">b_2 列和 lns="http://www.w3.org/1998/Math/MathML">b_2+1 列之间、…、第 lns="http://www.w3.org/1998/Math/MathML">b_L 列和第 lns="http://www.w3.org/1998/Math/MathML">b_L+1 列之间要开辟通道,其中lns="http://www.w3.org/1998/Math/MathML">b_i< b_{i+1},每两个整数之间用空格隔开(列尾没有空格)。

Sample Input Copy

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

Sample Output Copy

2
2 4

HINT

上图中用符号*、※、+标出了 lns="http://www.w3.org/1998/Math/MathML">3 对会交头接耳的学生的位置,图中 lns="http://www.w3.org/1998/Math/MathML">3 条粗线的位置表示通道,图示的通道划分方案是唯一的最佳方案。

2008 年普及组第二题