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

int main(){
	int N; cin>>N;
	vector<set<int>> tree(N);
	vi C;
	rp(i, 0, N-1){
		int p,c; cin>>p>>c; p--,c--;
		tree[p].insert(c); tree[c].insert(0);
		C.push_back(c);
	}

	int K = 0;
	vi p_color(N), visited(N);
	queue<int> q;
	q.push(0);
	visited[0] = true;
	while(!q.empty()){
		int p = q.front(); q.pop();
		K = max(K, (int)tree[p].size());
		int color = 1;
		for(auto c:tree[p]){
			if(visited[c]) continue;
			if(color == p_color[p]) color++;
			p_color[c] = color++;
			q.push(c);
			visited[c] = true;
		}
	}

	cout<< K <<endl;
	for(auto c:C) cout<< p_color[c] <<endl;
}