-132. Color Countries

I'm a slow walker, but I never walk backwards.

題目來源:judgegirl from ntu prof. pangfeng Liu

Task Description

Write a program to color the countries in a map. Imaging that you have a map, with countries in it. Your job is to color each country with a color, so that if two countries are adjacent, they will not have the same color. This problem will be trivial if the number of colors, denoted by , is unlimited, so we will limit the number of colors you can use. Note that there could be multiple sets of solution, and you only need to out one. If here is no solution, you only need to output "no solution.\n".

Input Format

The first line of the input has the number of countries, , and the number of colors you can use, , and the number of pairs of adjacent countries, P. Each country has an unique index from 0 to . The next lines describe pairs of countries that are adjacent, and each line has two indices of two adjacent countries. Both and are positive. is no more than 20 and is no more than 8.

Output Format

  • If there is a solution, output the color you assign to each country according to their indices. You should output exact lines, with i-th line being the color assignment of the country indexed as i - 1. Assignments are numbered from 1 to .
  • If there is no solution, output "no solution.\n".

Sample Input 1

5 3 7
0 1
0 4
1 2
1 3
1 4
2 3
3 4

Sample Output 1

1
2
3
1
3

Sample Input 2

4 3 6
0 1
0 2
0 3
1 2
1 3
2 3

Sample Output 2

no solution.

Submit

Login

Testdata Set

Download Testdata