#include <bits/stdc++.h>
using namespace std;
using  P=pair<long long,long long>;
int main(){
  long long N;
  cin>>N;
  vector<long long> A(N-1);
  vector<long long> B(N-1);
  vector<vector<long long>> vec(N,vector<long long>(0));
  vector<vector<long long>> color(N,vector<long long>(0));
  vector<unordered_map<long long,long long>> usedcolor(N);
  vector<long long> way(N);
  map<P,long long> mp;
  using Graph=vector<vector<int>>;
  Graph G(N);
  for(long long i=0;i<N-1;i++){
    long long a,b;
    cin>>a>>b;
    A.at(i)=a;
    B.at(i)=b;
    vec.at(a-1).push_back(b-1);
    vec.at(b-1).push_back(a-1);
    G[a-1].push_back(b-1);
    G[b-1].push_back(a-1);
  }
  long long maxusedcolor=0;
  for(long long i=0;i<N;i++){
    maxusedcolor=max(maxusedcolor,(long long)vec.at(i).size());
    //cout<<i<<" "<<vec.at(i).size()<<endl;
  }
  cout<<maxusedcolor<<endl;
  vector<long long> dist(N,-1);//全頂点を「未訪問」に初期化
  queue<long long> que;
  dist[0]=0;
  que.push(0);
  while(!que.empty()){
    long long v=que.front();//キューから先頭頂点を取り出す
    que.pop();
    //v から辿れる頂点をすべて調べる
    for(long long nv:G[v]){
      long long rock=0;
      //cout<<v<<" "<<nv<<endl;
      if(dist[nv]!=-1)continue;//すでに発見済みの頂点は探索しない
      if(color.at(v).size()==0){
        way.at(nv)=1;
        color.at(v).push_back(1);
        //sort(color.at(v).begin(),color.at(v).end());
        color.at(nv).push_back(1);
        //sort(color.at(nv).begin(),color.at(nv).end());
        usedcolor.at(v)[1]=1;
        usedcolor.at(nv)[1]=1;
        //cout<<v<<" "<<nv<<endl;
        mp[make_pair(v,nv)]=1;
      }
      else{
        if(usedcolor.at(v)[maxusedcolor]==0){
          way.at(nv)=maxusedcolor;
          color.at(v).push_back(maxusedcolor);
          //sort(color.at(v).begin(),color.at(v).end());
          color.at(nv).push_back(maxusedcolor);
          //sort(color.at(nv).begin(),color.at(nv).end());
          usedcolor.at(v)[maxusedcolor]=1;
          usedcolor.at(nv)[maxusedcolor]=1;
          //cout<<" "<<v<<" "<<nv<<endl;
          mp[make_pair(v,nv)]=maxusedcolor;
        }
        else{
          long long left=0,right=(long long)color.at(v).size()-1;
          rock=0;
          while(left<=right){
            long long mid=left+(right-left)/2;
            //cout<<v+1<<" "<<nv+1<<" "<<mid+1<<" "<<color.at(v).at(mid)<<endl;
            if(color.at(v).at(mid)>mid+1){right=mid-1;}
            else{left=mid+1;rock=max(rock,mid+1);}
          }
          rock++;
          //color.at(v).push_back(rock);
          color.at(v).insert(color.at(v).begin()+rock-1,rock);
          left=0,right=(long long)color.at(nv).size()-1;
          long long rocka=0;
          while(left<=right){
            long long mid=left+(right-left)/2;
            //cout<<v+1<<" "<<nv+1<<" "<<mid+1<<" "<<color.at(v).at(mid)<<endl;
            if(color.at(nv).at(mid)>rock){right=mid-1;}
            else{left=mid+1;rocka=max(rocka,mid+1);}
          }
          color.at(nv).insert(color.at(nv).begin()+rocka,rock);
          ////sort(color.at(v).begin(),color.at(v).end());
          //color.at(nv).push_back(rock);
          ////sort(color.at(nv).begin(),color.at(nv).end());
          usedcolor.at(v)[rock]=1;
          usedcolor.at(nv)[rock]=1;
          //cout<<"   "<<v<<" "<<nv<<endl;
          mp[make_pair(v,nv)]=rock;
        }
      }
      dist[nv]=dist[v]+1;
      que.push(nv);
    }
  }
  for(long long i=0;i<N-1;i++){
    cout<<mp[make_pair(A.at(i)-1,B.at(i)-1)]<<endl;
  }
}

Measured memory_bytes: 45504