#include<bits/stdc++.h>

#define  pf                  printf
#define  sc                  scanf
#define  PI                  2*acos(0.0)
#define  fast                ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define  mem(a,b)            memset(a, b, sizeof(a) )
#define  gcd(a,b)            __gcd(a,b)
#define  lcm(a,b)            (a*(b/gcd(a,b)))
#define  MAX                 1234567899
#define  mod                 1000000007
#define  all(v)              (v).begin(),(v).end()
#define  vSort(v)            sort(all(v))
#define  maxSort(v)          sort(all(v),greater<int>())
#define  Unique(v)           v.erase(unique(all(v)),v.end())
#define  sqr(x)              ((x)*(x))
#define  qube(x)             ((x)*(x)*(x))
#define  deci(n)             cout<<fixed<<setprecision(n)
#define  sci(n)              sc("%d",&(n))
#define  scii(x,y)           sc("%d %d",&(x),&(y))
#define  scl(x)              sc("%lld",&(x))
#define  scll(x,y)           sc("%lld %lld",&(x),&(y))
#define  vi                  vector<int>
#define  hi                  pf(" HI \n")
#define  pp                  pair<int,int>
#define  pb(x)               push_back(x)
#define  mp(x,y)             make_pair(x,y)
#define  F                   first
#define  S                   second
#define  check(n,pos)        (n & (1<<(pos)))
#define  biton(n,pos)        (n  (1<<(pos)))
#define  bitoff(n,pos)       (n & ~(1<<(pos)))
typedef  long long int       lli;
typedef  unsigned long long int ulli;
int dx4[] = { 0, 0, -1, 1 } ;
int dy4[] = { -1, 1, 0, 0 } ;
bool valid( int r, int c, int x, int y )
{
    if( x >= 1 && x <= r && y >= 1 && y <= c )
        return 1 ;
    return 0 ;
}

using namespace std;
int vis[100005];
map<pp,int>mp;
vi node[100005];
pp ppp;
int mx = -1;
void BFS(int u,int val)
{
    vis[u]= val;
    queue<int>q;
    q.push(u);
    while(!q.empty())
    {
        int v= q.front();
        q.pop();
        val=1;
        for(int i=0; i<node[v].size(); i++)
        {
          //  cout << vis[v]<< " vis "<<endl;
            if(vis[node[v][i]]==0)
            {
                ppp.F=v;
                ppp.S=node[v][i];

                q.push(node[v][i]);
                if(vis[v]==(i+1)){
                     //   cout << vis[v]<< " hgfdbhvd "<< val << " i "<< i+1<<endl;
                        val++;
                    vis[node[v][i]]=val;
                    mp[ppp]=val;
                    mx= max(mx,val);
                      //cout << ppp.F<< " ppp "<<ppp.S<< " "<< mp[ppp]<<endl;
                val++;
                    continue;}
                vis[node[v][i]]=val;
                mp[ppp]=val;
                  //cout << ppp.F<< " ppp "<<ppp.S<< " "<< mp[ppp]<<endl;
                  mx= max(mx,val);

                val++;
            }
        }
    }
}
int main ()
{
    int n;
        sci(n);

        int u,v;
        vector<pp>vec;
        for(int i=1; i<n; i++)
        {
            scii(u,v);
            node[u].pb(v);
            vec.pb(mp(u,v));
            //node[v].pb(u);
        }
        BFS(1,-1);
        cout << mx <<endl;
        for(int i=0;i<n-1;i++)
            {
                ppp=vec[i];
               // cout <<ppp.F<< " "<< ppp.S<< " ";
                cout <<mp[ppp]<<endl;
            }

    return 0;
}



Measured memory_bytes: 11892