Problem:
Score : 400 points

Problem Statement

Given is a tree G with N vertices.
The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i.

Consider painting the edges in G with some number of colors.
We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different.

Among the colorings satisfying the condition above, construct one that uses the minimum number of colors.

Constraints

2 \le N \le 10^5

1 \le a_i \lt b_i \le N

All values in input are integers.

The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
a_2 b_2
\vdots
a_{N-1} b_{N-1}

Output

Print N lines.

The first line should contain K, the number of colors used.

The (i+1)-th line (1 \le i \le N-1) should contain c_i, the integer representing the color of the i-th edge, where 1 \le c_i \le K must hold.

If there are multiple colorings with the minimum number of colors that satisfy the condition, printing any of them will be accepted.

Sample Input 1

3
1 2
2 3

Sample Output 1

2
1
2

Sample Input 2

8
1 2
2 3
2 4
2 5
4 7
5 6
6 8

Sample Output 2

4
1
2
3
4
1
1
2

Sample Input 3

6
1 2
1 3
1 4
1 5
1 6

Sample Output 3

5
1
2
3
4
5

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Time Limit Exceeded)

//--- pD ---//
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Scanner scanner;
	int mod = (int)1e9+7;

	public Solution() {
		scanner = new Scanner(System.in);

		// scanner.nextLine();
		while (scanner.hasNext()) {
			run_case();
		}
	}

	Map<Integer, Set<Integer>> adj;
	Map<String, Edge> edge_map;
	List<String> edges;
	Map<String, Integer> color = new HashMap<>();
	private void run_case() {
		// scanner.nextLine();
		String line = scanner.nextLine();
		int N = Integer.parseInt(line);
		// System.out.println(N);

		// build graph
		adj = new HashMap<>();
		edges = new ArrayList<>();
		edge_map = new HashMap<>();
		for (int i=0; i<N; i++) {
			adj.put(i, new HashSet<>());
		}
		for (int i=0; i<N-1; i++) {
			line = scanner.nextLine();
			// System.out.println(line);
			int a = Integer.parseInt(line.split("\\s+")[0]);
			int b = Integer.parseInt(line.split("\\s+")[1]);
			a --; b --;
			adj.get(a).add(b);
			adj.get(b).add(a);
			// Edge e1 = new Edge(a, b, 1);
			// Edge e2 = new Edge(b, a, 1);
			String key1 = String.valueOf(a) + "_" + String.valueOf(b);
			// String key2 = String.valueOf(b) + "_" + String.valueOf(a);
			// edge_map.put(key, e);
			// edge_map.put(key1, e1);
			// edge_map.put(key2, e2);
			edges.add(key1);
		}

		// find max vertex
		int max_edge = 0;
		for (int i=0; i<N; i++) {
			max_edge = Math.max(max_edge, adj.get(i).size());
		}

		// color
		dfs(0, -1, 0);

		// print res
		System.out.println(max_edge);
		for (String e : edges) {
			System.out.println(color.get(e) % max_edge + 1);
		}
		return;
	}

	private void dfs(int cur, int pv, int color_num) {
		// Edge e1 = new Edge(cur, pv, 1);
		// Edge e2 = new Edge(pv, cur, 1);
		String key1 = String.valueOf(cur) + "_" + String.valueOf(pv);
		String key2 = String.valueOf(pv) + "_" + String.valueOf(cur);
		// Edge e1 = edge_map.get(key1);
		// Edge e2 = edge_map.get(key2);

	    color.putIfAbsent(key1, color_num);
		color.putIfAbsent(key2, color_num);
		color.put(key1, color_num);
		color.put(key2, color_num);

		color_num ++;

		// if (adj.get(cur) != null) {
		    for (int nx : adj.get(cur)) {
				if (nx != pv){
		        	dfs(nx, cur, color_num++);
				}
		    }
		// }

		return;
	}

	private int[] strToIntArray(String str) {
	    String[] vals = str.split("\\s+");
	    int sz = vals.length;
	    int[] res = new int[sz];
	    for (int i=0; i<sz; i++) {
	        res[i] = Integer.parseInt(vals[i]);
	    }
	    return res;
	}
}

class Edge {
    public int u, v, w;
    public Edge(int u, int v, int w) {
        this.u = u;
        this.v = v;
        this.w = w;
    }
}