#include<bits/stdc++.h>
using namespace std;
int n,a[100010],b[100010],x[100010],ans,f[100010];
vector<int> g[100010];
map<pair<int,int>,int> mp;
void dfs(int deep,int color){
	int c=1;
	for (int i=0;i<g[deep].size();i++)
		if (f[g[deep][i]]==0){
			f[g[deep][i]]=1;
			if (c==color) c++;
			mp[pair<int,int>(g[deep][i],deep)]=c;
			mp[pair<int,int>(deep,g[deep][i])]=c;
			dfs(g[deep][i],c);
			c++;
		}
}
int main(){
	cin>>n;
	for (int i=0;i<n-1;i++){
		cin>>a[i]>>b[i];
		x[a[i]]++;x[b[i]]++;
		g[a[i]].push_back(b[i]);
		g[b[i]].push_back(a[i]);
	}
	for (int i=1;i<=n;i++) ans=max(ans,x[i]);
	cout<<ans<<endl;f[1]=1;
	dfs(1,-1);
	for (int i=0;i<n-1;i++) cout<<mp[pair<int,int>(a[i],b[i])]<<endl;
	return 0;
}