#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

vector<vector<pair<int, int>>> to;
vector<int> ans;

void dfs(int P, int C, int parent){
  int c = 1;
  for (auto i: to[P]){
    if (i.first == parent) continue;
    if (c == C) c++;
    ans[i.second] = c;
    dfs(i.first, c, P);
    c++;
  }
}

int main(){
  int n; cin >> n;
  to.resize(n);
  ans.resize(n-1);
  rep(i,n-1){
    int a, b; cin >> a >> b;
    a--; b--;
    to[a].push_back(make_pair(b,i));
    to[b].push_back(make_pair(a,i));
  }
  int K = 0;
  rep(i,n){
    K = max(K, (int)to[i].size());
  }
  cout << K << endl;

  dfs(0,0,-1);
  rep(i, n-1){
    printf("%d\n", ans[i]);
  }
}