#include <bits/stdc++.h>
using namespace std;

int n, res[(int)1e5], mx;
vector<pair<int, int> > adj[(int)1e5 + 1];
bool vis[(int)1e5 + 1];

void color(int vtx, int pre){//pre前面已用颜色 
	vis[vtx] = true;
	int col = 1;
	for(int i=0;i<adj[vtx].size(); i++)
		if(!vis[adj[vtx][i].first]){
			if(col == pre) col++;
			res[adj[vtx][i].second] = col, mx = max(mx, col);
			color(adj[vtx][i].first, col++);// col先赋值 再++                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
		}
}

int main(){
    cin >> n;
    for(int i = 1; i < n; i++){
    	int a, b;
    	cin >> a >> b;
    	adj[a].push_back({b, i});
    	adj[b].push_back({a, i});
    }
    color(1, 0);
    cout << mx << "\n";
    for(int i = 1; i <= n - 1; i++) cout << res[i] << "\n";
    return 0;
}

Measured memory_bytes: 8448