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

const int N=1e5+20;

int n,u,v,ans[N];
vector <pair <int,int>> adj[N];

void dfs(int node,int parent,int old_color)
{
	int current_color=1;
	for(auto p:adj[node])
	{
		int child=p.first,edge=p.second;
		if(child==parent) continue;
		if(current_color==old_color) current_color++;
		ans[edge]=current_color;
		dfs(child,node,current_color);
		current_color++;
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n-1;i++)
	{
		scanf("%d%d",&u,&v);
		adj[u].push_back({v,i});
		adj[v].push_back({u,i});
	}

	dfs(1,0,0);
	printf("%d\n",*max_element(ans,ans+n-1));
	for(int i=0;i<n-1;i++) printf("%d\n",ans[i]);
}