#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<pair<int,int> > adj[1000000];
int col[1000000];
int mx=0;
void dfs(int v,int p,int cant){
    int cur = 1;
    for (auto u:adj[v]){
        if (u.first==p)continue;
        while(cur==cant)cur++;
        mx=max(mx,cur);
        col[u.second]=cur++;
        dfs(u.first, v, cur-1);
    }
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    for (int i=1;i<n;i++){
        int a,b;
        cin>>a>>b;
        adj[a].push_back({b,i});
        adj[b].push_back({a,i});
    }
    dfs(1,0,0);
    cout<<mx<<endl;
    for (int i=1;i<n;i++)cout<<col[i]<<endl;
}