#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

vector<vector<P>> T;
int visit[100010] = {};
int res[100010];

int dfs(int n,int ng){
  visit[n] = 1;
  int col = 1;
  int ncol = 0;
  for(P edge : T[n]){
    if(visit[edge.first])continue;
    if(col == ng)col++;
    res[edge.second] = col;
    ncol = max(ncol, dfs(edge.first, col));
    col++;
  }
  return max(ncol, col-1);
}

int main(void){
  int n;
  cin >> n;
  T = vector<vector<P>>(n);
  for(int i = 0;i < n-1;++i){
    int a,b;
    scanf("%d %d", &a, &b);
    --a;--b;
    T[a].push_back(P(b,i));
    T[b].push_back(P(a,i));
  }
  int ncol = dfs(0,0);
  printf("%d\n", ncol);
  for(int i = 0;i < n-1;++i){
    printf("%d\n", res[i]);
  }
  return 0;
}
