Edges coloring

4

1 votes
Medium, Algorithms, Approved
Problem

You are given connected undirected graph with n vertices and m edges.

Let's say that mapping between edges and positive integers f(e) is good mapping if following conditions are true:

  1. For each pair of edges e1 and e2 (e1e2) holds f(e1)f(e2);
  2. Let's define the set of all edges incident to v as N(v). If size of N(v) is greater than 1, then gcdf(e)eN(v)=1.

Your task is to find good mapping that maxeE(f(e)) is minimum as possible.

Input format

The first line contains three integers n and m (2n2105, 1m2105) — number of vertices and number of edges, respectively.

Then m lines follow.

The i-th of them contains integers ai and bi (1ai,bin, aibi) describing edge ei connecting ai and bi.

Output format

First line of output should contain single integer maxeE(f(e)) of your mapping f.

Then print m lines: the i-th of these lines should contain single integer f(ei).

Time Limit: 2
Memory Limit: 512
Source Limit:
Explanation
  • N(1)=(1,4)
  • N(2)=(1,2)
  • N(3)=(2,3)
  • N(4)=(3,4)
Editor Image

?