#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
 
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<pair<int,int>> E(N-1);
  vector<int> M(N+1);
  vector<int> nodec(N);  
  vector<int> edgec(N-1);  
  for (auto &[f,t]: E) {
    cin >> f >> t;
    ++M[--f];
    ++M[--t];
  }
 
  vector<int> I(N-1);
  iota(begin(I),end(I),0);
  sort(begin(I),end(I),[&](int i, int j){return E[i] < E[j];});
  int NC = *max_element(begin(M),end(M));
  cout << NC << endl;
  nodec[1] = 0;
  for (auto i: I) {
    auto [f,t] = E[i];
    nodec[f] %= NC;
    edgec[i] = nodec[t] = ++nodec[f];
  }
 
  for(auto c: edgec) cout << c << endl;
}