#include <bits/stdc++.h>
using namespace std;

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}

//Graph in adjcency list
struct Graph{
    struct Edge{
        int from;
        int to;
        ll cost;
        Edge(int a, ll b) : to(a), cost(b) {}
        Edge(int a, int b, ll c) : from(a), to(b), cost(c) {}
    };

    int N;  //頂点数
    vector<vector<Edge>> adjlist;   //隣接リスト
    vector<ll> dist;   //ノードの深さ
    ll diam;            //木の直径
    vector<int> deg;    //入次数
    vector<int> cycle;  //サイクル
    map<pair<int,int>,int> colormap;
    int maxcolor;

    Graph(int n) : N(n), adjlist(n), dist(n, INF), diam(INF), deg(n, 0), maxcolor(0){}

    void setEdge(int a, int b, ll c){   //辺を追加
        adjlist[a].push_back(Edge(a, b, c));
        deg[b]++;
    }

    bool visited(int v){
        return dist[v] < INF;
    }

    void resetDist(){
        for(int i=0; i<N; i++){
            dist[i] = INF;
        }
    }

    void dfs(int p, int v, int color){    //深さ優先探索
        if(visited(v)) return;

        dist[v] = 1;

        int c = 0;

        for(auto e : adjlist[v]){
            if(e.to == p) continue;
            c++;
            if(c == color) c++;
            chmax(maxcolor, c);
            colormap[make_pair(e.from, e.to)] = c;
            dfs(v, e.to, c);
        }
    }

    void bfs(int v){        //幅優先探索
        queue<Edge> que;
        for(auto i : adjlist[v]) que.push(i);

        dist[v] = 0;

        while(!que.empty()){
            int u = que.front().to;
            ll d = que.front().cost;
            que.pop();

            dist[u] = d;

            for(auto e : adjlist[u]){
                if(!visited(e.to)){
                    que.push(Edge(e.to, d + e.cost));
                }
            }
        }
    }

    ll diameter(){  //木の直径を求める
        if(diam != INF) return diam;  //計算済みの場合

        dfs(-1, 0, 0);  //頂点0からの最遠頂点vを求める
        int v = max_element(all(dist)) - dist.begin();

        resetDist();

        dfs(-1, v, 0);  //vからの最遠頂点を求める

        return diam = MAX(dist);   //この2頂点間の距離が直径
    }

    void dijkstra(int start){   //ダイクストラ法
        dist[start] = 0;

        auto fn = [](Edge a, Edge b){return a.cost > b.cost;};
        priority_queue<Edge, vector<Edge>, decltype(fn)> que(fn);

        for(auto e : adjlist[start]) que.push(e);

        while(!que.empty()){
            auto v = que.top().to;
            auto d = que.top().cost;
            que.pop();

            if(visited(v)) continue;
            else dist[v] = d;
            
            for(auto e : adjlist[v]){
                if(dist[e.to] == INF){
                    que.push(Edge(e.to, e.cost + d));
                }
            }
        }
    }

    bool BellmanFord(int start){    //ベルマンフォード法 (負の閉路がある場合はtrueを返す)
        dist[start] = 0;
        REP(i, N){
            REP(j, N){
                for(auto k : adjlist[j]){
                    if(visited(j) && dist[j] + k.cost < dist[k.to]){
                        if(i == N-1) return true;  //N回目にも更新があるなら負の閉路が存在
                        dist[k.to] = dist[j] + k.cost;
                    }
                }
            }
        }
        return false;
    }

    vector<int> topologicalSort(){ //トポロジカルソート
        queue<int> que;
        REP(i, N){
            if(deg[i] == 0) que.push(i);
        }

        vector<int> result;

        while(!que.empty()){
            auto v = que.front();
            que.pop();
            result.push_back(v);
            for(auto e : adjlist[v]){
                deg[e.to]--;
                if(deg[e.to] == 0) que.push(e.to);
            }
        }
        
        return result;
    }

    void findCycle(int p, int v) {
        static vector<bool> seen(N, false), finished(N, false);
        static int pos = -1;

        seen[v] = true;
        cycle.push_back(v);

        for(auto e : adjlist[v]){
            if(e.to == p || finished[e.to]) continue;
            if(seen[e.to] && !finished[e.to]){
                pos = e.to;
                return;
            }
            findCycle(v, e.to);

            if(pos != -1) return;
        }

        cycle.pop_back();
        finished[v] = true;
    }
};


signed main(){
    int n;
    cin >> n;
    Graph G(n);

    vector<Graph::Edge> edges;

    REP(i, n-1){
        int a, b;
        cin >> a >> b;
        edges.emplace_back(Graph::Edge(a-1, b-1, 1));
    }

    for(auto e : edges){
        G.setEdge(e.from, e.to, e.cost);
        G.setEdge(e.to, e.from, e.cost);
    }

    G.dfs(-1, 0, 0);

    cout << G.maxcolor << endl;
    REP(i, n-1){
        auto p = make_pair(edges[i].from, edges[i].to);
        cout << G.colormap[p] << '\n';
    }

    return 0;
}


Measured memory_bytes: 16880