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

const int maxn=200007;
int n;
vector<pair<int,int> > e[maxn];
int ans[maxn],ret;

void dfs(int u,int p,int col){
    int j=1;
    for (auto c:e[u]){
        if (c.first==p) continue;
        if (j==col) j++;
        ans[c.second]=j;
        dfs(c.first,u,j);
        j++;
    }
}

int main(){
    scanf("%d",&n);
    for (int i=1;i<n;++i){
        int u,v;
        scanf("%d%d",&u,&v);
        e[u].push_back({v,i});
        e[v].push_back({u,i});
    }
    for (int i=1;i<=n;++i){
        ret=max(ret,(int)e[i].size());
    }
    dfs(1,-1,-1);
    printf("%d\n",ret);
    for (int i=1;i<n;++i){
        printf("%d\n",ans[i]);
    }
    return 0;
}