Graph Coloring
시간 제한2초메모리 제한1024 MB
차수가 5 이하인 무방향 그래프의 각 정점을 3가지 색으로 칠하되, 모든 정점이 같은 색인 이웃을 최대 하나만 갖도록 색을 배정하고, 불가능하면 -1을 출력한다.
문제
You are given a bidirectional graph where the degree of each vertex is at most 5. Paint its vertices in 3 colors in such a way that each vertex has no more than one neighbor of the same color as .
입력
On the first line, there are two integers and : the number of vertices and the number of edges ().
Each of next lines contains two integers and : the numbers of vertices connected by an edge ().
It is guaranteed that there are no loops or multiple edges in the graph, and the degree of each vertex is at most 5.
출력
It there is no valid coloring, print one number "-1" (without quotes). Otherwise, print integers , , , : the colors of all vertices (). If there is more than one solution, print any one of them.