#include<bits/stdc++.h>
            using namespace std;
            #define ll long long int
            #define ull unsigned long long
            ll power(ll,ll);
            ll ncr(ll,ll);
            ll add(ll a,ll b);
            void fact();
            ll mul(ll a,ll b);
            #define watch(x) cerr<<(#x)<<"is"<<x<<nl;
            #define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
            #define fi(a,b) for(ll i=a; i<b; i++)
            #define fk(a,b) for(ll k=a; k<b; k++)
            #define fri(a,b) for(ll i=a; i>=b; i--)
            #define fj(a,b) for(ll j=a; j<b; j++)
            #define ffi(a,b) for(ll i=a;i*i<=b;i++)
            #define mp make_pair
            #define ff first 
            #define  tc ll t; cin>>t; while(t--)
            #define all(v) (v).begin(),(v).end()
            #define ss second
            #define pb push_back
            #define mem(v,a) memset((v),a,sizeof(v));
            #define pll pair<ll,ll>
            #define mll map<ll,ll>
            #define sll set<ll>
            #define vll vector<ll>
            #define max3(a,b,c) max(a,max(b,c))
            #define min3(a,b,c) min(a,min(b,c))
            #define nl endl
             int mod=1e9+7;
            const ll  N=100032LL;
            ll fac[N+2];
            ll inv[N+2];
            vll adj[N];
            map<pll,ll> m;
            vll col;
            ll vis[N];
            
           void dfs(int s,int past){
			   
			   vis[s]=1;
			   ll d=0;
			   for(auto u:adj[s]){
				
				if(!vis[u]){
					if(col[d]==past) d++; 
						m[mp(s,u)]=col[d];
						dfs(u,col[d]);
					d++;
					 
				}
				   
			   }
		   }
           
            
            signed main(){  
        	fast
        	//~ fact();
        	//~ tc
            { ll n; cin>>n;
				vll a(n-1),b(n-1);
				
				fi(0,n-1){
					cin>>a[i]>>b[i];
					adj[a[i]].pb(b[i]);
					adj[b[i]].pb(a[i]);
				}
			 
			 ll ml=0,in=0;
			 fi(1,n+1){ if(ml<(ll)adj[i].size()) ml=max(ml,(ll)adj[i].size()),in=i;} 
			 
			 fi(1,ml+1) col.pb(i);
			 
			 
			 	dfs(in,-1);
			  	
			  	cout<<ml<<nl;
			  	fi(0,n-1)cout<<max(m[mp(a[i],b[i])],m[mp(b[i],a[i])])<<nl; 
			  	
    		    
    	     }
                return 0;
            }
             
             
            /******************************************************************************/
             
            ll add(ll a,ll b){
    			a+=b;
    		   if(a>=mod) a-=mod;
    		   if(a<0) a+=mod;
    		   return a;
    		} 
             
            ll mul(ll a,ll b){
                return ((a)*(b))%mod;
            }
             
            ll power(ll a,ll n){
              ll res=1;
              while(n){
                  if(n&1) res= mul(res,a);
                 n>>=1; 
                 a= mul(a,a);
              }
                return res;
            }
            void fact(){
            	inv[0]=fac[0]=1;
            	fi(1,N){
            	 fac[i]=mul(fac[i-1],i);
            	inv[i]=power(fac[i],mod-2);
            }
            }
             
            ll ncr(ll n,ll r){
            	
            	if(r>n) return 0;
            	ll e=fac[n];
            	e=mul(e,inv[r]);
            	e=mul(e,inv[n-r]);
            	return e;
            }


Measured memory_bytes: 22400