/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

//code by lynmisakura.wish to be accepted!
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

/***************************/
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<long long> vl;
typedef pair<ll, ll> pi;
typedef vector<pair<ll, ll>> vpi;

//const long long INF = 1LL << 55;

#define itn ll
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(ll i = 0;i < n;i++)
#define rep(i,n) for(ll i = 0;i < n;i++)
#define flush fflush(stdout)
#define rrep(i,n) for(ll i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define ioboost cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, ll mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

class DColoringEdgesOnTree {
public:
    static constexpr int kStressIterations = 0;
    static void generateTest(std::ostream& test) {
    }

    vector<int> edge[100100];
    int visited[100010];
    int A[100010],B[100010];
    void solve(std::istream& cin, std::ostream& cout) {
        int n;cin >> n;
        rep(i,n-1){
            int a,b;cin >> a >> b;

            edge[--a].pb(--b);
            edge[b].pb(a);
            A[i]  = a;
            B[i] = b;
        }

        map<pair<int,int>,int> ans;

        queue<int> q;
        q.push(0);
        while(!q.empty()){
            int x = q.front();
            visited[x]++;
            q.pop();
            //int c = 1;
            int sz = edge[x].size();
            set<int> col;
            rep(i,sz)col.insert(i+1);
            for(auto j : edge[x]){
                int aa = min(x,j),bb = max(x,j);
                if(ans[pair<int,int>(aa,bb)] != 0){
                    if(col.find(ans[pair<int,int>(aa,bb)]) != col.end()){
                        col.insert(*(col.end()) + 1);
                        col.erase(ans[pair<int,int>(aa,bb)]);
                    }
                }
            }
            for(auto j : edge[x]){
                int aa = min(x,j),bb = max(x,j);
                if(ans[pair<int,int>(aa,bb)] == 0){ans[pair<int,int>(aa,bb)] = *col.begin();col.erase(col.begin());}
                if(!visited[j])q.push(j);
                
            }
            
        }
        int k = 0;
            for(auto i : ans){maxs(k,i.second);}
            
            
            printf("%d",k);cout <<endl;
            //cout << k << endl;
            //for(auto i:ans)cout <<i.second << endl;
            //cout << endl;
            for(int i = 0;i < n-1;i++){
                int aa = min(A[i],B[i]);
                int bb = max(A[i],B[i]);
                cout << ans[pair<int,int>(aa,bb)] << endl;
               // cout << endl;
            }

    }
};
int main() {
	DColoringEdgesOnTree solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 13440