#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(int)(cnt); ++(var))
#define REP(var,init,cnt) for(int (var)=(init); (var)<=(int)(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define bet(min,var,max) (min)<=(var)&&(var)<=(max)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) ((flag)?1:0)
#define YN(flag) cout<<(flag?"YES":"NO")<<endl;
#define Yn(flag) cout<<(flag?"Yes":"No")<<endl;
#define yn(flag) cout<<(flag?"yes":"no")<<endl;
#define Cout(v) cout<<(v)
#define COUT(v) cout<<(v)<<endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<p.first<<" "<<p.second;
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<" ";
  }
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<" ";
  }
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

// Usual Template End ===================

// Template End =========================

constexpr int MOD=1e9+7;
using mint = ModInt<MOD>;
locale LOCATE=locale::classic();

template<typename T>
void chmax(T &a,T b){if(a<b){a=b;}};

int main(void){
  int N; cin>>N;
  mat<int> G(N);
  vec<pi> ed(N-1);
  map<pi,int> de;
  rep(i,N-1){
    int a,b; cin>>a>>b; --a,--b;
    ed[i]=pi(a,b); de[pi(a,b)]=i,de[pi(b,a)]=i;
    G[a].emplace_back(b),G[b].emplace_back(a);
  }

  int K=0;
  rep(i,N) chmax(K,(int)G[i].size());

  mat<bool> next(N,vec<bool>(K,true));
  cout<<K<<endl;
  if(K>2){ 
    rep(i,N-1){
      int a,b; tie(a,b)=ed[i];
      int c=0;
      while(!(next[a][c]&&next[b][c])) ++c;
      cout<<c+1<<endl;
      next[a][c]=next[b][c]=false;
    }
  }
  else{
    queue<pi> q; q.emplace(0,0);
    vec<pi> ans;
    vec<bool> used(N,false);
    while(!q.empty()){
      int now,c; tie(now,c)=q.front(); q.pop();
      used[now]=true;
      rep(i,G[now].size()){
        int nv=G[now][i];
        if(used[nv]) continue;
        ans.emplace_back(de[pi(now,nv)],c+1);
        q.emplace(nv,c^1);
      }
    }
    SORT(ans);
    rep(i,N-1){
      cout<<ans[i].second<<endl;
    }
  }
}














Measured memory_bytes: 324348