#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <algorithm>
#include <sstream>
#include <climits>
#include <fstream>
#include <cmath>

using namespace std;

/// ********* debug template by Bidhan Roy *********

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const unordered_set< T > &v ) {
    os << "[";
    typename unordered_set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << ": " << it -> second ;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const unordered_map< F, S > &v ) {
    os << "[";
    typename unordered_map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << ": " << it -> second ;
    } 
    return os << "]";
}

#define debug(x) cerr << #x << " = " << x << endl;

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
typedef vector<bool> VB;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<LL> VLL;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<VB> VVB;
typedef vector<VI> VVI;
typedef vector<VC> VVC;
typedef vector<VLL> VVLL;
typedef vector<VD> VVD;
typedef vector<VS> VVS;

// TEMPLATE DEFINITIONS END

int n, u, v;
VVI g;
vector<PII> input;
void read_input(){

    cin >> n;
    g.resize(n, VI());
    for(int i=0;i<n-1;i++){
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
        input.push_back({u, v});
    }
}

void solve(){

    unordered_map<int, unordered_map<int, int>> edge_colors;

    VB visited(n, false);
    queue<int> q;
    q.push(0);
    visited[0] = true;
    int max_color = 0;
    while(!q.empty()){

        int curr = q.front(); q.pop();
        VI colors;
        for(auto neigh : g[curr]){
            if(edge_colors[curr].count(neigh))
                colors.push_back(edge_colors[curr][neigh]);
        }
        sort(colors.begin(), colors.end());

        int c = 1, j=0;
        for(int i=0;i<g[curr].size();i++){
            int neigh = g[curr][i];
            if(!colors.size() || (colors.size() && colors[j] != c && !edge_colors[curr].count(neigh))){
                edge_colors[curr][neigh] = c;
                edge_colors[neigh][curr] = c;
                max_color = max(max_color, c);
                c++;
                q.push(neigh);
                visited[neigh] = true;
            }else
            if(colors.size() && colors[j] == c && !edge_colors[curr].count(neigh)){
                j++;
                c++;
                i--;
            }
        }
    }

    cout << max_color << "\n";
    for(auto edge : input){
        cout << edge_colors[edge.first][edge.second] << "\n";
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    read_input();
    solve();
    return 0;
}


Measured memory_bytes: 26104