#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 2147483647;
int prime = 998244353;
void Debug(auto a);
double PI = 3.14159265358979;
void input(vector<auto>& a,int n);
int n;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> siz;

    UnionFind(int N) : par(N), siz(N, 1LL) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    int size(int x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

struct Edge{
    int from,to,cost;
    bool operator<(const Edge& another) const{
        return cost < another.cost;
    }
    bool operator>(const Edge& another) const{
        return cost > another.cost;
    }
};

class uGrapf{
    public:
    vector<vector<P>> grapf;
    vector<int> d,ord,low;
    vector<P> _bridge;
    bool loop = false;
    uGrapf(int n){
        this->grapf.resize(n);
        this->d.resize(grapf.size(),LONG_LONG_MAX);
    }
    uGrapf(){
        this->grapf.resize(10e6);
        this->d.resize(grapf.size(),LONG_LONG_MAX);
    }
    /* 辺の二つ、コストの順
     */
    void edge(int edge1,int edge2,int weight=1){
        P p = P(edge2,weight);
        grapf[edge1].push_back(p);
        p = P(edge1,weight);
        grapf[edge2].push_back(p);
    }
    void atc(vector<int> &a,vector<int> &b,int s){
        int c = 1;
        REP(i,grapf[s].size()){
            if(a[grapf[s][i].first]) continue;
            if(a[s] == c) c++;
            a[grapf[s][i].first] = c;
            b[grapf[s][i].first] = s;
            atc(a,b,grapf[s][i].first);
            c++;
        }
        // return a;
    }
};

signed main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    cin >> n;
    uGrapf g(n);
    vec(cnt,n);
    vector<P> p(n-1);
    REP(i,n-1){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        cnt[a]++;
        cnt[b]++;
        g.edge(a,b);
        p[i] = P(a,b);
    }
    int x = 0;
    REP(i,n){
        x = max(x,cnt[i]);
    }
    print(x);
    vec(c,n);
    vec(d,n);
    c[0] = -1;
    g.atc(c,d,0);
    // Debug(d);
    REP(i,n-1){
        if(p[i].first == d[p[i].second]){
            print(c[p[i].second]);
        }
        else{
            print(c[p[i].first]);
        }
    }

    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}

void input(vector<auto>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


Measured memory_bytes: 15228