#include<bits/stdc++.h>
using namespace std;
vector<unordered_set<int>> tree;
vector<pair<int,int>> edge;
map<pair<int,int>,int> color;
int max_color=0;

void comp(int p){
  for (auto i: tree[p]){
    tree[i].erase(p);
    comp(i);
  }
  return;
}

void paint(int p, int pre){
  int c=0;
  for (auto i: tree[p]){
    c++;
    if (c==pre) c++;
    color[make_pair(min(p,i),max(p,i))]=c;
    paint(i,c);
  }
  max_color=max(max_color,c);
  return;
}

int main(){
  int n,a,b;
  cin>> n;
  tree.assign(n,{});
  edge.assign(n-1,pair<int,int>());
  for (int i=0; i<n-1; i++){
    cin>> a >> b; a--; b--;
    tree[a].insert(b); tree[b].insert(a);
    edge[i]=make_pair(a,b);
  }
  comp(0);
  paint(0,0);
  cout<<max_color<<endl;
  for (auto i: edge) cout<<color[i]<<endl;
}