#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cassert>

#include<cmath>
#include<functional>
#include<algorithm>

#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<bitset>
#include<tuple>

#define TEST {IS_TEST=true;}

using namespace std;
using ll = int_fast64_t;
using v_bool = vector <bool>;
using v_ll = vector <ll>;
using v_std = vector <string>;
using p_ll = pair <ll,ll>;
using vv_ll = vector <vector <ll> >;
using vp_ll = vector < p_ll >;

using ld = long double;
using v_ld = vector <ld>;
using vv_ld = vector<v_ld>;

bool IS_TEST=false;
ll ll_min=1LL<<63;
ll ll_max=~ll_min;
ll int_min=1LL<<31;
ll int_max=~ll_max;
ll MOD = 1000000007;

template<class T>
void show(const T &x){
  if (!IS_TEST) return;
  cout << x << endl;
}
template<class T1,class T2>
void show(const pair<T1,T2> &x){
  if (!IS_TEST) return;
  cout << "{" << x.first << "," << x.second << "}" << endl;
}

template<class T>
void show_sub(const T &x){if (!IS_TEST) return; cout << x;}
void show_sub(const string &x){if (!IS_TEST) return; cout << x << endl;}
template<class T1,class T2>
void show_sub(const pair<T1,T2> &x){
  if (!IS_TEST) return;
  cout << "{" << show_sub(x.first) << "," << show_sub(x.second) << "}";
}
template<class T>
void v_show(const T &v){
  if (!IS_TEST) return;
  auto itr=v.begin();
  while(itr!=v.end()){ show_sub(*itr); itr++;}
  cout << endl;
}

template<class T>
void vv_show(const T &v){
  if (!IS_TEST) return;
  cout << "--------------------------------\n";
  auto itr=v.begin();
  while(itr!=v.end()){ v_show(*itr); itr++;}
  cout << "--------------------------------" << endl;
}



ll max(ll x,ll y){return x>y?x:y;}
ll max(ll x,ll y, ll z){return max(max(x,y),z);}
ll max(v_ll::iterator b,v_ll::iterator e){
    ll ans=*b;
    while (b<e) {ans=max(ans,*b);b++;}
    return ans;
}
ll min(ll x,ll y){return x<y?x:y;}
ll min(ll x,ll y, ll z){return min(min(x,y),z);}
ll min(v_ll::iterator b,v_ll::iterator e){
    ll ans=*b;
    while (b<e) {ans=min(ans,*b);b++;}
    return ans;
}
ll mid(ll x,ll y,ll z){
    if (y>=x && x>=z) return x;
    if (z>=x && x>=y) return x;
    if (x>=y && y>=z) return y;
    if (z>=y && y>=x) return y;
    if (x>=z && z>=y) return z;
    if (y>=z && z>=x) return z;
    return x;
}
ll gcd(ll x,ll y){
    if(x<0)x=-x; if(y<0)y=-y;
    while(y>0){ x%=y; swap(x,y); }
    return x;
}
ll gcd(ll x,ll y, ll z){return gcd(gcd(x,y),z);}
ll gcd(v_ll::iterator b,v_ll::iterator e){
    ll ans=0;
    while (b<e) ans=gcd(ans,*b);
    return ans;
}
ll lcm(ll x,ll y){
    ll z=x*y; if(x<0)x=-x; if(y<0)y=-y;
    while(y>0){ x%=y; swap(x,y); }
    return z/x;
}
ll lcm(ll x,ll y, ll z){return lcm(lcm(x,y),z);}
ll lcm(v_ll::iterator b,v_ll::iterator e){
    ll ans=1;
    while (b<e) ans=lcm(ans,*b);
    return ans;
}

v_ll arange(ll n){
    v_ll v(n+1,0);
    for(ll i=0;i<=n;i++)v[i]=i;
    return v;
}

ll vec_sum(const v_ll& v,ll b,ll e){
    ll ans=0;
    for(ll i=b;i<e;i++)ans+=v[i];
    return ans;
}
ll v_sum(v_ll::iterator b,v_ll::iterator e){
    ll ans=*b;
    while (b<e) { ans+=*b; b++;}
    return ans;
}
ll v_xor(v_ll::iterator b,v_ll::iterator e){
    ll ans=*b;
    while (b<e) { ans^=*b; b++;}
    return ans;
}
ll v_eq(v_ll::iterator b,v_ll::iterator e){
    ll ans=*b;
    while (b<e) { ans^=~*b; b++;}
    return ans;
}


template<class T> void refl_max(T& x,const T& y){ if (x>=y) return; x=y; }
template<class T> void refl_min(T& x,const T& y){ if (x<=y) return; x=y; }

template<class T,class S> void refl_max(T& x,S& xx,const T& y,const S& yy){
  if (x>=y) return; x=y; xx=yy;
}
template<class T,class S> void refl_min(T& x,S& xx,const T& y,const S& yy){
  if (x<=y) return; x=y; xx=yy;
}

template<class T> void quit(T x){cout << x << endl; exit(0);}

/*O(logN)*/
ll sqrt_ll(ll n){
  assert(n>=0);
  ll ok = 0,ng = n+1;
  while(ok-ng>1||ng-ok>1){ ll m=(ok+ng)/2; if (m*m<=n) ok=m; else ng=m;}
  return ok;
}


class Neighbor{
    public:
    bool dir;
    ll from,to,edge;
    Neighbor(ll w,ll x,ll y,bool z){from=w;to=x;edge=y;dir=z;}
    inline operator ll()const{ return to;} 
};
class Node{
    public:
    vector<Neighbor> neighbor;
    bool valid; ll idx;
    Node(bool v,ll i){valid=v;idx=i;}
    inline Neighbor& operator[](ll n){ return neighbor[n];}
    inline vector<Neighbor>::iterator begin(){ return neighbor.begin();}
    inline vector<Neighbor>::iterator end(){ return neighbor.end();}
    inline void push_back(ll w,ll x,ll y, bool z){neighbor.push_back(Neighbor(w,x,y,z));}
    inline ll size(){return neighbor.size();}
    /*----------------*/
};
class Edge{
    public:
    bool valid;  bool indir;
    ll n1,n2; ll idx;
    Edge(bool v,ll i,ll x,ll y,bool z){valid=v;idx=i;n1=x;n2=y;indir=z;}
    /*----------------*/

};
class Graph{
    public:
    vector<Node> n;
    vector<Edge> e;
    void init(ll nodes, ll idx_node, ll idx_edge){
        n.clear(); e.clear();
        for (ll i=0;i<idx_node;i++) n.push_back(Node(false,n.size()));
        for (ll i=0;i<idx_edge;i++) e.push_back(Edge(false,e.size(),-1,-1,true));
        for (ll i=0;i<nodes;i++) n.push_back(Node(true,n.size()));
    }
    ll edge(ll f, ll t, bool indir=true){
        assert(f>=0&&f<n.size()&&t>=0&&t<n.size());
        ll i=e.size();e.push_back(Edge(true,i,f,t,!indir));
        n[f].push_back(f,t,i,true);
        n[t].push_back(t,f,i,indir);
        return i;
    }
    ll d_edge(ll f, ll t){return edge(f,t,false);}
    inline Node& operator[](ll x){ return n[x];} 

    void show(){
        for (ll i=0;i<n.size();i++){
            if(!n[i].valid)continue;
            cout << i << "\t";
            for(ll j=0;j<n[i].size();j++){
                if (n[i][j].dir) cout << n[i][j].to << " ";
            }
            cout << endl;
        }
    }
};

class Data{
  public:
  ll to,col,edge;
  Data (ll x,ll y,ll z){
    to=x;col=y;edge=z;
  }
};

ll N;
v_bool A;
v_ll col;
int main(){
  cin >> N;
  Graph G;
  A.assign(N+10,false);
  col.assign(N+10,0);
  G.init(N,1,1);
  for(ll i=0;i<N-1;i++){
    ll x,y;
    cin >> x >> y;
    G.edge(x,y);
  }
  queue<Data> que;
  que.push(Data(1,-1,-1));
  while(!que.empty()){
    Data f = que.front();
    que.pop();
    if (A[f.to])continue;
    A[f.to]=true;
    if (f.edge>=0)col[f.edge]=f.col;
    ll color=1;
    for(ll i=0;i<G[f.to].size();i++){
      ll moveto = G[f.to][i];
      if (A[moveto]) continue;
      if (f.col==color)color++;
      que.push(Data(moveto,color,G[f.to][i].edge));
      //cout << moveto << " " << color << " " << G[f.to][i].edge<< endl;
      color++;
    }
    //cout << endl;
  }
  ll K=1;
  for (ll i=1;i<=N;i++){
    refl_max(K,col[i]);
  }
  cout << K << endl;
for (ll i=1;i<N;i++){
    cout << col[i] << endl;
  }
}




Measured memory_bytes: 18412