#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
using namespace std;


template<class V, class E> class Graph
{
	public:
		int nodes;
		vector<pair<int,int> > edges;
		map<int,vector<int> > edgemap;
		map<int, V> v_color;
		map<pair<int,int>, E> e_color;
		void inspect(void);
		void resize(int);
		void push_diedge(int, int);
		void push_biedge(int, int);
		void dfs(void (*func)(Graph<V,E> &, int), int);
};


template <class V, class E> void Graph<V,E>::dfs(void (*func)(Graph<V,E> &, int), int firstnode){
	stack<int> s;
	int n_size = this->nodes;
	vector<int> visited(n_size,0);
	s.push(firstnode);
	visited[firstnode] = 1;
	while(!s.empty()){
		int v = s.top();
		s.pop();
		func(*this, v);//shori
		vector<int> adjnodes = this->edgemap[v];
		for(int i=0; i<=adjnodes.size()-1; i++){
			if(visited[adjnodes[i]] == 0){
				visited[adjnodes[i]] = 1;
				s.push(adjnodes[i]);
			}
		}
	}
	return;
}

template <class V, class E> void Graph<V,E>::resize(int n){
	this->nodes = n;
	return;
}
template <class V, class E> void Graph<V,E>::push_diedge(int n, int m){
	int gsize = this->nodes;
	if(n >= gsize || m >= gsize || n < 0 || m < 0){
		cerr << "no such vertex" << endl;
		exit(1);
	}
	pair<int,int> p = make_pair(n,m);
	this->edges.push_back(p);
	if(this->edgemap.count(n) == 0){
		vector<int> hoge;
		hoge.push_back(m);
		this->edgemap[n] = hoge;
	}else{
		this->edgemap[n].push_back(m);
	}
	return;
}
template <class V, class E> void Graph<V,E>::push_biedge(int n, int m){
	this->push_diedge(n,m);
	this->push_diedge(m,n);
	return;
}
template <class V, class E> void Graph<V,E>::inspect(){
	int n_size = this->nodes;
	int e_size = this->edges.size();
	cout << "nodes:" << endl;
	for(int i=0; i<=n_size-1; i++){
		cout << i <<" [" << this->v_color[i] << "]" << endl;
	}
	cout << "edges:" << endl;
	for(int i=0; i<=e_size-1; i++){
		int f = (this->edges[i]).first;
		int s = (this->edges[i]).second;
		printf("(%d,%d): ",f,s);
		cout << this->e_color[edges[i]] << endl;
	}
	return ;
}



void my_echo(Graph<int,int> &G, int n){
	vector<pair<int,int> > adjedges;
	for(int i=0; i<=G.edgemap[n].size()-1; i++){
		pair<int,int> hoge = make_pair(n,G.edgemap[n][i]);
		adjedges.push_back(hoge);
	}
	//for(int i=0; i<=adjedges.size()-1; i++){
	//	printf("(%d,%d)\n",adjedges[i].first,adjedges[i].second);
	//}
	vector<int> kinsi_colors;
	for(int i=0; i<=adjedges.size()-1; i++){
		if(G.e_color.count(adjedges[i]) >= 1){
			//printf("kinsi:%d\n",G.e_color[adjedges[i]]);
			kinsi_colors.push_back(G.e_color[adjedges[i]]);
		}
	}
	sort(kinsi_colors.begin(), kinsi_colors.end());
	kinsi_colors.push_back(100000000);
	int cnt = 1;
	int kinsi_bango = 0;
	for(int i=0; i<=adjedges.size()-1; i++){
		if(G.e_color.count(adjedges[i]) == 0){
			while(cnt == kinsi_colors[kinsi_bango]){
				cnt++;
				kinsi_bango++;
			}
			G.e_color[adjedges[i]] = cnt;
			pair<int,int> rev = make_pair(adjedges[i].second, adjedges[i].first);
			G.e_color[rev] = cnt;
			cnt++;
		}
	}
	//printf("\n");
	return;
}

int main(){
	Graph<int,int> hoge;
	scanf("%d",&(hoge.nodes));
	vector<pair<int,int> > nds(hoge.nodes - 1);
	for(int i=0; i<=hoge.nodes-2; i++){
		int s,t;
		scanf("%d %d",&s, &t);
		nds[i].first = s-1;
		nds[i].second = t-1;
		hoge.push_biedge(nds[i].first, nds[i].second);
	}

	hoge.dfs(my_echo, 0);
	int colornum = 0;
	for(int i=0; i<=hoge.edges.size()-1; i++){
		if(hoge.e_color[hoge.edges[i]] > colornum){
			colornum = hoge.e_color[hoge.edges[i]];
		}
	}
	cout << colornum << endl;
	for(int i=0; i<=hoge.nodes-2; i++){
		cout << hoge.e_color[nds[i]];
		if(i != hoge.nodes-2){
			cout << endl;
		}
	}
	//hoge.inspect();
	return 0;
}


Measured memory_bytes: 23664