/**
 *   created: 24 November 2019  09:33:01
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define int long long
#define PB push_back
#define PPB pop_back
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================
int d(int n){
	int cnt=0;
	while(n){
		n /= 10;
		cnt++;
	}
	return cnt;
}
int32_t main()
{
	optimizeIO();
	int tt=1;
	//cin>>tt;
	while(tt--){
		int n;
		cin>>n;
		vector< vector<int> >  adj(n+1);
		vector< pair<int,int> > v(n-1);
		rep(i,0,n-1){
			cin>>v[i].first>>v[i].second;
			adj[v[i].first].push_back(v[i].second);
			adj[v[i].second].push_back(v[i].first);
		}
		int k=0;
		vector< pair<int,int> > deg(n+1);
		deg[0].first = INF;
		rep(i,1,n+1){
			k = max(k, (ll)adj[i].size());
			deg[i].first = adj[i].size();
			deg[i].second = i;
		}
		sort(all(deg));
		reverse(all(deg));
		// trace1(k);
		map< pair<int,int>, int> m;
		queue< pair<int,int> > q;
		q.push(make_pair(1,-1));
		vector<int> vis(n+1,0);
		while(q.size()){
			auto tp = q.front();
			q.pop();
			if(vis[tp.first])
				continue;
			vis[tp.first] = 1;
			int temp = k;
			for(int x:adj[tp.first]){
				if(vis[x])
					continue;
				while(temp==tp.second)
					temp--;
				m[make_pair(min(x,tp.first), max(x,tp.first))] = temp--;
				q.push(make_pair(x,temp+1));
			}
		}
		// rep(i,1,n+1){
		// 	trace2(deg[i].second, deg[i].first);
		// 	int temp = k;
		// 	for(auto t:adj[deg[i].second]){
		// 		int x = min(deg[i].second,t), y = max(deg[i].second,t);
		// 		if(m.find(make_pair(x,y))!=m.end())
		// 			continue;
		// 		m[make_pair(x,y)] = temp--;
		// 	}
		// }
		cout<<k<<endl;
		rep(i,0,n-1)
			cout<<m[make_pair(min(v[i].first, v[i].second), max(v[i].first, v[i].second))]<<endl;
	}

	return 0;
}


Measured memory_bytes: 16896