// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
//#include <bits/stdc++.h>

#define all(v) v.begin(), v.end()
typedef long long ll;
#define rep(i, z, n) for(int i = z; i < n; i++)
//const int INF = 1<<29;
//const ll MOD = 1000000007;
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<vector<int>> con(N + 1, vector<int>(0));
    map<vector<int>, int> mp;
    
    rep(i, 0, N - 1){
        int a, b;
        cin >> a >> b;
        con.at(a).push_back(b);
        con.at(b).push_back(a);
        mp[{a, b}] = i;
    }
   
    int K = 0;
    int rootG = 0;
    rep(i, 1, N + 1){
        if(con.at(i).size() > K){
            K = con.at(i).size();
            rootG = i;
        }
    }
    cout << K << endl;
    
    queue<int> q;
    vector<bool> reach(N + 1, false);
    vector<set<int>> S(N + 1);
    vector<int> ans(N, 0);
    q.push(rootG);
    reach.at(rootG) = true;
    int i = 1;
    while(!q.empty()){
        int rootA = q.front();
        q.pop();
        for(int x : con.at(rootA)){
            
            if(!reach.at(x)){
                int start = i;
                while(true){
                    if(!(S.at(rootA).count(i) || S.at(x).count(i))){
                        int a, b;
                        if(mp.count({rootA, x})){
                            a = rootA;
                            b = x;
                        }
                        else{
                            a = x;
                            b = rootA;
                        }
                        ans.at(mp[{a, b}]) = i;
                        S.at(a).insert(i);
                        S.at(b).insert(i);
                        break;
                    }
                    i++;
                    if (i == start) break;
                    if (i == K + 1) i = 1;
                }
                q.push(x);
                reach.at(x) = true;
            }
        }
    }
    rep(i, 0, N - 1){
        cout << ans.at(i) << endl;
    }
}

Measured memory_bytes: 33972