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 Rust (1.15.1) (judge verdict: Time Limit Exceeded)

//use itertools::Itertools;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: usize,
        edge: [(usize,usize);n-1]
    }

    let mut ans = 0;

    let mut adj_list: Vec<Vec<usize>> = vec![Vec::new(); n];
    for e in &edge {
        adj_list[e.0 - 1].push(e.1 - 1);
        adj_list[e.1 - 1].push(e.0 - 1);
    }

    let mut colors = 0;

    let mut edge_colors: Vec<HashMap<usize, usize>> = vec![HashMap::new(); n];

    let root = 0;

    let mut visited: Vec<bool> = vec![false; n];
    let mut queue: VecDeque<usize> = VecDeque::new();
    queue.push_back(root);

    // 使用した色を管理
    let mut used_colors: Vec<Vec<bool>> = vec![vec![false; n + 1]; n];

    while queue.len() > 0 {
        let vertex = queue.pop_front().unwrap();
        let vertex_colors = adj_list[vertex].len();
        colors = cmp::max(colors, vertex_colors);

        if !visited[vertex] {
            visited[vertex] = true;
            for v in &adj_list[vertex] {
                if !visited[*v] {
                    queue.push_back(*v);
                }

                if edge_colors[vertex].get(v) != None {
                    //println!("{},{}", vertex + 1, *v + 1);
                    continue;
                }

                let mut color = 0;
                for i in 0..vertex_colors {
                    if !used_colors[vertex][i + 1] && !used_colors[*v][i + 1] {
                        color = i + 1;
                        break;
                    }
                }
                used_colors[vertex][color] = true;
                used_colors[*v][color] = true;

                //println!("{},{} {}", vertex + 1, *v + 1, color);

                edge_colors[vertex].insert(*v, color);
                edge_colors[*v].insert(vertex, color);
            }
        };
    }
    //println!("{:?}", used_colors);
    //println!("{:?}", edge_colors);

    println!("{}", colors);

    for e in &edge {
        println!("{}", edge_colors[e.0 - 1].get(&(e.1 - 1)).unwrap());
    }
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet