#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
char memarr[96000000];
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
struct graph{
  int N;
  int *es;
  int **edge;
  void setEdgeRootedTree(int N__, int M, int A[], int B[], int root=0, int reorder=0, int cnv[] = NULL, void **mem = &wmem){
    int i;
    int j;
    int k;
    int *dist;
    int *q;
    int qs;
    int qe;
    int *ind;
    void *tmem;
    N = N__;
    tmem = ((char*)(*mem)) + (sizeof(int) * N + 15) + (sizeof(int*) * N + 15) + (sizeof(int) * M + 15 * N);
    walloc1d(&es, N, mem);
    walloc1d(&edge, N, mem);
    for(i=(0);i<(N);i++){
      es[i] = 0;
    }
    for(i=(0);i<(M);i++){
      es[A[i]]++;
      es[B[i]]++;
    }
    for(i=(0);i<(N);i++){
      walloc1d(&edge[i], es[i], &tmem);
    }
    for(i=(0);i<(N);i++){
      es[i] = 0;
    }
    for(i=(0);i<(M);i++){
      edge[A[i]][es[A[i]]++] = B[i];
      edge[B[i]][es[B[i]]++] = A[i];
    }
    walloc1d(&dist, N, &tmem);
    walloc1d(&q, N, &tmem);
    walloc1d(&ind, N, &tmem);
    if(cnv==NULL){
      walloc1d(&cnv, N, &tmem);
    }
    for(i=(0);i<(N);i++){
      dist[i] = -1;
    }
    dist[root] = 0;
    qs = qe = 0;
    q[qe++] = root;
    while(qs < qe){
      i = q[qs++];
      for(j=(0);j<(es[i]);j++){
        k = edge[i][j];
        if(dist[k]==-1){
          dist[k] = dist[i] + 1;
          q[qe++] = k;
        }
      }
    }
    if(reorder == 0){
      for(i=(0);i<(N);i++){
        cnv[i] = i;
      }
      for(i=(0);i<(N);i++){
        ind[i] = i;
      }
    }
    else{
      for(i=(0);i<(N);i++){
        cnv[i] = q[i];
      }
      for(i=(0);i<(N);i++){
        ind[cnv[i]] = i;
      }
    }
    for(i=(0);i<(N);i++){
      es[i] = 0;
    }
    for(i=(0);i<(M);i++){
      j = A[i];
      k = B[i];
      if(dist[j] > dist[k]){
        swap(j, k);
      }
      es[ind[j]]++;
    }
    for(i=(0);i<(N);i++){
      walloc1d(&edge[i], es[i], mem);
    }
    for(i=(0);i<(N);i++){
      es[i] = 0;
    }
    for(i=(0);i<(M);i++){
      j = A[i];
      k = B[i];
      if(dist[j] > dist[k]){
        swap(j, k);
      }
      j = ind[j];
      k = ind[k];
      edge[j][es[j]++] = k;
    }
  }
}
;
int N;
int A[100000];
int B[100000];
map< pair<int,int>,int > mp;
graph g;
int ress;
int res[100000];
int solve(int n, int c){
  int Lj4PdHRW;
  int k = 1;
  for(Lj4PdHRW=(0);Lj4PdHRW<(g.es[n]);Lj4PdHRW++){
    auto &i = g.edge[n][Lj4PdHRW];
    if(k==c){
      k++;
    }
    res[mp[make_pair(n,i)]] = k;
    solve(i, k++);
  }
}
int main(){
  int i;
  wmem = memarr;
  rd(N);
  {
    int e98WHCEY;
    for(e98WHCEY=(0);e98WHCEY<(N-1);e98WHCEY++){
      rd(A[e98WHCEY]);A[e98WHCEY] += (-1);
      rd(B[e98WHCEY]);B[e98WHCEY] += (-1);
    }
  }
  for(i=(0);i<(N-1);i++){
    mp[make_pair(A[i],B[i])] = mp[make_pair(B[i],A[i])] = i;
  }
  g.setEdgeRootedTree(N,N-1,A,B);
  solve(0, 0);
  {
    int WYIGIcGE;
    int t_ynMSdg;
    if(N-1==0){
      t_ynMSdg = 0;
    }
    else{
      t_ynMSdg = res[0];
      for(WYIGIcGE=(1);WYIGIcGE<(N-1);WYIGIcGE++){
        t_ynMSdg = max_L(t_ynMSdg, res[WYIGIcGE]);
      }
    }
    ress =t_ynMSdg;
  }
  wt_L(ress);
  wt_L('\n');
  {
    int tU__gIr_;
    for(tU__gIr_=(0);tU__gIr_<(N-1);tU__gIr_++){
      wt_L(res[tU__gIr_]);
      wt_L('\n');
    }
  }
  return 0;
}
// cLay varsion 20191123-1

// --- original code ---
// int N, A[1d5], B[1d5];
// 
// map< pair<int,int>,int > mp;
// graph g;
// int ress, res[1d5];
// 
// int solve(int n, int c){
//   int k = 1;
//   rep[g.edge[n]](i, g.es[n]){
//     if(k==c) k++;
//     res[mp[make_pair(n,i)]] = k;
//     solve(i, k++);
//   }
// }
// 
// {
//   rd(N,(A--,B--)(N-1));
//   rep(i,N-1) mp[make_pair(A[i],B[i])] = mp[make_pair(B[i],A[i])] = i;
// 
//   g.setEdgeRootedTree(N,N-1,A,B);
//   solve(0, 0);
// 
//   ress = max(res(N-1));
//   wt(ress);
//   wtLn(res(N-1));
// }


Measured memory_bytes: 21120