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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
//#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
void accum(Vi &v){REP(i,1,(v).size()) v[i]+=v[i-1];}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}


void solve(long long n, std::vector<long long> a, std::vector<long long> b){
    REP(i,0,n-1){a[i]--;b[i]--;}

    map<int,int> ma;
    REP(i,0,n-1){
        ma[a[i]]++;
        ma[b[i]]++;
    }
    int ans=0;
    for(auto x : ma) chmax(ans,x.second);
    cout<<ans<<endl;

    VPii edge(n-1);
    REP(i,0,n-1) edge[i]=mp(a[i],b[i]);
    map<Pii,int> color;
    REP(i,0,n-1) color[edge[i]]=0;


    Vi used(n,0);
    used[0]=ans+1;
    Vi iro(n,0);
    VVi connect(n);
    REP(i,0,n-1){
        connect[a[i]].pb(b[i]);
        connect[b[i]].pb(a[i]);
    }

    queue<Tiii> q;
    q.push(mt(0,-1,0));
    while(!q.empty()){
        int now,past,dnow;
        tie(now,past,dnow)=q.front();
        q.pop();
        //なんらかの処理;
        REP(i,0,connect[now].size()){
            if(connect[now][i]!=past){
                int next=connect[now][i];
                if(connect[next].size()>1) q.push(mt(next,now,dnow+1));
                if(iro[now]<used[now]){
                    color[mp(now,next)]=iro[now];
                    color[mp(next,now)]=iro[now];
                    used[next]=iro[now];
                    iro[now]++;
                }else{
                    color[mp(now,next)]=iro[now]+1;
                    color[mp(next,now)]=iro[now]+1;
                    used[next]=iro[now]+1;
                    iro[now]++;
                }
            }
        }
    }
    REP(i,0,n-1) cout<<color[edge[i]]+1<<endl;

    REP(i,0,n-1){

    }

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N-1);
    std::vector<long long> b(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
    }
    solve(N, std::move(a), std::move(b));
    return 0;
}


Measured memory_bytes: 29952