// D - Coloring Edges on Tree
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	vector<int> tree[N];
	int C[N-1];
	rp(i, 0, N-1){
		int p; scanf("%d%d", &p, C+i); p--,C[i]--;
		tree[p].push_back(C[i]);
	}

	int K = 0;
	int colors[N]; rp(i, 0, N) colors[i] = 0;

	queue<int> q;
	q.push(0);
	colors[0] = -1;
	while(!q.empty()){
		int p = q.front(); q.pop();
		int color = 1;
		for(auto c:tree[p]){
			if(colors[c]) continue;
			q.push(c);
			colors[c] = color==colors[p]? ++color: color;
			K = max(K, color++);
		}
	}

	printf("%d\n", K);
	for(int c:C) printf("%d\n", colors[c]);
}