#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
ll const N=1e6+5;
ll const INF=1e18;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define len length()
#define mp make_pair
#define mt make_tuple
#define acc(v) accumulate(all(v), 0)
#define F first
#define S second
 
#define forz(i, n) for (ll i = 0; i < n; i++)
#define fore(i, m, n) for (ll i = m; i <= n; i++)
#define rforz(i, n) for (ll i = n - 1; i >= 0; i--)
#define rfore(i, m, n) for (ll i = n; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define highll(n) __builtin_popcountll(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define gcd __gcd
#define sexy ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
 
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
 
#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order

bool comp(pair <ll,ll> p1,pair <ll,ll> p2){
    if(p1.F>p2.F){
        return true;
    }else{
        return false;
    }
}

vector<vector<pair<ll,ll>>> adj(N); 
ll ax[N];
ll ap[N];

ll h[N];
void dfs(ll x,ll y){
    for(auto u:adj[x]){
        if(u.F==y) continue;
        h[u.F]=h[x]-1;
        dfs(u.F,x);
    }
}

int main(){
    sexy;
    ll T,x,y,z,p,q,r,s,t;
    cin>>x;
    ll ar[2][x-1];
    map <pair<ll,ll>,pair<ll,ll>> mp;
    forz(i,x-1){
        cin>>p>>q;
        mp[{p,q}]={adj[p].si,adj[q].si};
        mp[{q,p}]={adj[q].si,adj[p].si};
        ax[p]++;
        ax[q]++;
        ar[0][i]=p;
        ar[1][i]=ap[p];
        ap[p]++;
        ap[q]++;
        adj[p].pb({q,-1});
        adj[q].pb({p,-1});
    }
    z=0;
    fore(i,1,x){
        if(ax[i]>z){
            z=ax[i];
            p=i;
        }
    }
    h[p]=x;
    dfs(1,0);
    vector <pair<ll,ll>> vp;
    fore(i,1,x){
        vp.pb({h[i],i});
    }
    sort(all(vp),comp);
    vector <ll> v;
    for(auto it:vp){
        v.pb(it.S);
    }
    set <ll> se;
    for(auto it:v){
        if(ax[it]==1&&it!=v[0]){
            continue;
        }
        fore(i,1,ax[it]){
            se.insert(i);
        }
        for(auto l:adj[it]){
            if(l.S!=-1){
                if(se.find(l.S)!=se.end()){
                    se.erase(l.S);
                }
            }
        }
        for(auto l:adj[it]){
            if(l.S==-1){
                ll k=mp[{it,l.F}].S;
                ll n=mp[{it,l.F}].F;
                adj[it][n].S=(*se.begin());
                adj[l.F][k].S=(*se.begin());
                se.erase(*se.begin());
            }
        }
    }
    p1(z);
    forz(i,x-1){
        p1(adj[ar[0][i]][ar[1][i]].S);
    }
    return 0;
}


Measured memory_bytes: 58612