1716. Vera and Dogs

时间限制 2000 ms   内存限制 512 MB

Vera owns N doghouses numbered from 1 to N and M = X·N dogs numbered from 1 to M. Each doghouse should be the primary home of X dogs Pi,1, . . . , Pi,X and the secondary home of X dogs Si,1, . . . , Si,X. Each dog should have one primary home and one secondary home different from its primary home. Every night, at most one doghouse might be unavailable due to cleaning. Each dog will sleep in its primary home if it is available, otherwise it will sleep in its secondary home. Each doghouse should contain at most X + 1 sleeping dogs on any night. 

Help Vera find a valid assignment of doghouses to dogs, or determine that it is impossible. 

输入数据

Line 1 contains integers N and X (1 ≤ N, X ≤ 2017, X · N ≤ 50000). 

输出数据

If it is impossible to find a valid assignment, print one line with -1. 

Otherwise print N lines. The i-th line should contain 2X integers Pi,1, . . . , Pi,X, Si,1, . . . , Si,X. If there are multiple possible assignments, print any of them. 

样例输入

复制
3 2 
 · \n

样例输出 special judge

复制
5 1 6 4
3 6 5 2
4 2 1 3
 · · · \n
 · · · \n
 · · · \n

样例说明

For the example: 

Doghouse 1 is the primary home of dogs 5 and 1 and secondary home of dogs 6 and 4. If doghouse 1 is unavailable, then dog 1 will sleep in doghouse 3 and dog 5 will sleep in doghouse 2. 

Doghouse 2 is the primary home of dogs 3 and 6 and secondary home of dogs 5 and 2. If doghouse 2 is unavailable, then dog 3 will sleep in doghouse 3 and dog 6 will sleep in doghouse 1. 

Doghouse 3 is the primary home of dogs 4 and 2 and secondary home of dogs 1 and 3. If doghouse 3 is unavailable, then dog 4 will sleep in doghouse 1 and dog 2 will sleep in doghouse 2. 

So it can be seen that no doghouse will ever contain more than 3 dogs. 

Another Example:

for input:

2 2

the output should be:

-1

提交

请先 登录

© 2025 FAQs Contact About