This page is still under construction.

Parts of this page are still being built. What you see may change.

Agents

Time limit1sMemory limit128 MB

Summary
Given a graph of dislikes where at most three agents touch everyone else, decide whether the vertices 3-color into at most three independent sets and output the lexicographically smallest coloring.
Level

Hard8 of 10

Topics
Graph, DFS, Backtracking, Greedy
Solved
No attempts yet

Problem

A secret organization must assign every one of its agents to a team. Some pairs of agents cannot work together, so no team may contain a pair of agents who dislike each other. Because of the nature of the mission, the agents can be divided into at most three teams.

The organization has a few especially difficult members — at least one and at most three of them — and every other agent dislikes at least one of these difficult members. Thanks to this structure, deciding whether a valid division exists is always solvable in polynomial time.

Given the agents and the pairs who cannot work together, decide whether the agents can be split into at most three teams so that no team contains a disliking pair, and if so, report the assignment.

Input

The input consists of several test instances.

The first line of each instance contains two integers AA and RR (1≤A≤5001 \le A \le 500, 0≤R0 \le R), separated by a space. AA is the number of agents, numbered from 00 to A−1A-1, and RR is the number of pairs of agents who dislike each other. Each of the next RR lines contains two integers a1a_1 and a2a_2 (0≤a1,a2<A0 \le a_1, a_2 < A), meaning that agents a1a_1 and a2a_2 dislike each other. Each such pair is listed exactly once.

A blank line follows each instance. The input ends with a line containing two zeros.

Output

For each instance, print one line.

If the agents can be split into at most three teams so that no team contains a pair who dislike each other, print AA integers separated by single spaces: the ii-th integer (for ii from 00 to A−1A-1) is the team number in {0,1,2}\{0, 1, 2\} assigned to agent ii. Among all valid assignments, print the lexicographically smallest sequence of team numbers.

If no such division exists, print the string The agents cannot be split.

Examples3

  1. Example 1

    Input
    3 3
    0 1
    0 2
    2 1
    
    4 6
    0 1
    0 2
    0 3
    1 2
    1 3
    2 3
    
    0 0
    
    Expected output
    0 1 2
    The agents cannot be split
    
  2. Example 2

    Input
    1 0
    
    0 0
    
    Expected output
    0
    
  3. Example 3

    Input
    2 1
    0 1
    
    0 0
    
    Expected output
    0 1