// D - Coloring Edges on Tree
#include <bits/stdc++.h>
using namespace std;
#define NMAX 100000

int K = 1;
vector<vector<int>> tree(NMAX);
int colors[NMAX], visited[NMAX];

void dfs(int p, int p_color){
	int color = 1;
	for(int c:tree[p]){
		if(visited[c]) continue;
		visited[c] = true;
		colors[c] = color==p_color? ++color: color;
		K = max(K, color);
		dfs(c, color++);
	}
}

int main(){
	int N; cin>>N;
	int C[N-1];
	for(int i=0; i<N-1; ++i){
		int p; scanf("%d%d", &p, C+i); p--,C[i]--;
		tree[p].push_back(C[i]);
		tree[C[i]].push_back(p);
	}
	visited[0] = true;
	dfs(0, -1);
	printf("%d\n", K);
	for(int c:C) printf("%d\n", colors[c]);
}