import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = rint;

	Node[] nodes;
	foreach(i; 0 .. n) nodes ~= new Node(i);

	X[] edges;
	foreach(i; 0 .. n){
		int a = rint - 1, b = rint - 1;
		edges ~= X(a, b);
		nodes[a].nodes ~= nodes[b];
		nodes[b].nodes ~= nodes[a];
		nodes[a].deg += 1;
		nodes[b].deg += 1;
	}

	int maxd;
	foreach(nd; nodes) maxd = max(maxd, nd.deg);

	nodes[0].treefy(null);
	nodes[0].paint(-1);

	int[] ans;
	foreach(ed; edges){
		Node nda = nodes[ed.a], ndb = nodes[ed.b];
		if(nda.parent && nda.parent.id == ndb.id){
			ans ~= nda.value;
		}
		else ans ~= ndb.value;
	}

	maxd.writeln;
	ans.map!(to!string).array.join(" ").writeln;

}
struct X{
	int a, b;
}
class Node{
	int id;
	int deg;
	int value; // 親からの色
	Node[] nodes;
	Node[] sons;
	Node parent;
	this(int id){
		this.id = id;
	}
	void treefy(Node par){
		if(par) this.parent = par;
		foreach(nd; nodes){
			if(par && par.id == nd.id) continue;
			else{
				sons ~= nd;
				nd.treefy(this);
			}
		}
	}
	void paint(int col){
		this.value = col;
		int i = 1;
		foreach(nd; nodes){
			if(parent && parent.id == nd.id) continue;
			if(i == col) i += 1;
			nd.paint(i);
			i += 1;
		}
	}
}