#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;
const int Max_Num=100010;
typedef pair<int,int> P;

int col[Max_Num];
vector<P> G[Max_Num];
int K;

void dfs(int n, int color){
	int c=1;
	rep(i,G[n].size()){
		if(col[G[n][i].second]!=-1) continue;
		if(c==color) c++;
		K=max(K,c);
		col[G[n][i].second]=c;
		dfs(G[n][i].first,c);
		c++;
	}
}

int main(){
	int N;
	cin >> N;
	rep(i,N-1){
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].emplace_back(make_pair(b,i));
		G[b].emplace_back(make_pair(a,i));
	}
	rep(i,N-1) col[i]=-1;
	K=0;
	dfs(0,0);
	cout << K << endl;
	rep(i,N-1) cout << col[i] << endl;

  return 0;
}
