Neighbors and colors P31278


Statement
 

pdf   zip

You are given a graph with nn vertices and mm edges. Your task is to paint each vertex with one of CC colors. Your coloring must be such that no vertex xx has more than VV adjacent vertices with the same color as xx.

Input

Input consists of several cases. Every case begins with nn, CC, VV, and mm. Follow the mm edges. There are no repeated edges, nor edges connecting xx to xx. The vertices are numbered starting from zero. Assume 2n10002 \le n \le 1000, C1C \ge 1, and that the number of neighbors of every vertex is strictly less than C(V+1)C(V + 1), which will be at most 20.

Output

Print CC lines for every case. In the ii-th line, print the vertices such that their color is ii. Print the vertices in any order, and separated by one space. Print an additional final line with 10 asterisks after each case. If there are several solutions, you may print any of them. If there is no solution, print an elegant proof that P=NPP = NP.

Public test cases
  • Input

    3 1 1 1
    2 0
    2 1 0 0
    4 3 0 4
    0 1  1 2  2 3  3 0
    4 3 0 4
    0 1  1 2  2 3  3 0
    4 2 1 4
    0 1  2 1  0 2  0 3
    6 2 2 15
    0 1  0 2  0 3  0 4  0 5  1 2  1 3  1 4
    1 5  2 3  2 4  2 5  3 4  3 5  4 5
    

    Output

    0 1 2
    **********
    0 1
    **********
    
    3 1
    0 2
    **********
    3
    1
    0 2
    **********
    0 2
    1 3
    **********
    0 2 4
    1 3 5
    **********
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++