Problem:
Score : 400 points

Problem Statement

Given is a tree G with N vertices.
The vertices are numbered 1 through N, and the i-th edge connects Vertex a_i and Vertex b_i.

Consider painting the edges in G with some number of colors.
We want to paint them so that, for each vertex, the colors of the edges incident to that vertex are all different.

Among the colorings satisfying the condition above, construct one that uses the minimum number of colors.

Constraints

2 \le N \le 10^5

1 \le a_i \lt b_i \le N

All values in input are integers.

The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
a_2 b_2
\vdots
a_{N-1} b_{N-1}

Output

Print N lines.

The first line should contain K, the number of colors used.

The (i+1)-th line (1 \le i \le N-1) should contain c_i, the integer representing the color of the i-th edge, where 1 \le c_i \le K must hold.

If there are multiple colorings with the minimum number of colors that satisfy the condition, printing any of them will be accepted.

Sample Input 1

3
1 2
2 3

Sample Output 1

2
1
2

Sample Input 2

8
1 2
2 3
2 4
2 5
4 7
5 6
6 8

Sample Output 2

4
1
2
3
4
1
1
2

Sample Input 3

6
1 2
1 3
1 4
1 5
1 6

Sample Output 3

5
1
2
3
4
5

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include "bits/stdc++.h"
#define _USE_MATH_DEFINES
#include <math.h>
 
using namespace std;
 
using LL = long long;
using VLL = std::vector<LL>;
using VVLL = std::vector<VLL>;
using VVVLL = std::vector<VVLL>;
using LD = long double;
using VLD = std::vector<LD>;
using VVLD = std::vector<VLD>;
using VVVLD = std::vector<VVLD>;
 
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; }return false; }

#define REP(i,n) for(LL (i)=0;(i)<(n);(i)++)
#define ALL(v) v.begin(), v.end()
#define PRINTLN(v) {LL i=0; for(auto (a): v ){   cerr <<i << " : "<<  a << endl; i++;}}
#define PRINTSP(v) for(auto (a): v ) {cerr << a << " ";} cerr << endl
#define cmax(a,b) {if(a<b){a=b;}}
#define cmin(a,b) {if(a>b){a=b;}}
//#define cmax(a,b) a = (a>b ? a:b)
//#define cmin(a,b) a = (a<b ? a:b) 

struct To{
  LL to;
  LL id;
};

vector<vector<To>> to;
vector<LL> edge_color;
void dfs(LL v , LL p=-1, LL pColor = -1){
  //cerr <<setw(3)<<p  << "  -> " << setw(3)<< v <<setw(3)<< pColor << endl;
  LL color = 0;
  REP(i,to[v].size()){
    LL u = to[v][i].to;
    LL id = to[v][i].id;
    if(u==p){
      continue;
    }
    if(color==pColor){
      color++;  
    }
    edge_color[id]=color;
    //!  エッジに対する処理 A
    dfs(u,v,color);
    //!  エッジに対する処理 B
    color++;
  }
}


void func() {
  LL N;
  cin >> N;
  to.resize(N);
  edge_color.resize(N-1);
  REP(i,N-1){
    LL a,b;
    cin >>a;
    cin >>b;
    a--;
    b--;
    To t;
    t.to = b;
    t.id = i;
    
    to[a].push_back(t);
    t.to = a;
    to[b].push_back(t);
  }
  LL K=0;
  for(auto t: to){
    //PRINTSP(t);
    chmax(K,(LL)t.size());
  }
  
  dfs(0,-1,-1);
  cout << K << endl;
  for(auto ec : edge_color){
    cout << ec+1 << endl;
  }

  return;
}

 
int main()
{
  func();
  return 0;
}