## Yet Another Contest 4 P3 - Canadian Cactus Competition

View as PDF

Points: 12 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

Nils is participating in the Canadian Cactus Competition (CCC)! Whilst the other competitors have brought their prized tall cacti, all dressed up with costumes and googly eyes, Nils has brought in something truly beautiful - a cactus graph!

The graph contains nodes labelled from to , and edges. The -th edge is bidirectional and connects nodes and . Since the graph is a cactus, each edge belongs to at most one cycle.

Each of the nodes has a value, which is an integer between and (inclusive). Each edge has a colour equal to the bitwise XOR of the values of the nodes it connects. The beauty of the graph is the smallest colour of any edge in the graph.

The values of the nodes have not yet been finalised, so to boost his chances of winning first place, Nils wants to find the maximum possible beauty of the graph, and any possible allocation of values to nodes which achieves this beauty.

#### Constraints

There is at most one edge between any pair of nodes.

The graph is connected.

. That is, is one less than a power of two.

#### Input Specification

The first line of input contains three space-separated integers, .

The -th of the following lines of input contains two space-separated integers, .

#### Output Specification

The first line of output should contain the maximum possible beauty of the graph.

The second line of output should contain space-separated integers, with the -th integer representing the colour of the -th node.

If there are multiple valid answers, output any of them.

#### Sample Input

4 4 2
1 2
2 3
1 3
3 4

#### Sample Output

1
0 1 2 0

#### Explanation

The first edge has a colour of .

The second edge has a colour of .

The third edge has a colour of .

The fourth edge has a colour of .

Here, denotes the bitwise XOR operator.

Then, the beauty of the graph is . It can be shown that this is the maximum possible beauty.