#include<bits/stdc++.h>

#define ll              long long int
#define ull             unsigned long long int
#define pii             pair < int, int>
#define pll             pair < ll, ll>
#define sc              scanf
#define scin(x)         sc("%d",&(x))
#define scln(x)         sc("%lld",&(x))
#define pf              printf
#define NL              pf("\n")
#define ms(a,b)         memset(a,b,sizeof(a))
#define pb(a)           push_back(a)
#define mp              make_pair
#define db              double
#define EPS             10E-10
#define ff              first
#define ss              second
#define sqr(x)          (x)*(x)
#define vi              vector< int >
#define vl              vector< ll >
#define vii             vector<vector< int > >
#define vll             vector<vector< ll > >
#define DBG             pf("HI\n")
#define MOD             1000000007
#define CIN             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define RUN_CASE(t,T)   for(__typeof(t) t=1;t<=T;t++)
#define CASE(t)         printf("Case %d: ",t)
#define CASEL(t)        printf("Case %d:\n",t)
#define intlimit        2147483648
#define longlimit       9223372036854775808
#define infinity        (1<<28)
#define gcd(a, b)       __gcd(a,b)
#define lcm(a, b)       ((a)*(b)/gcd(a,b))
#define mx              1234567899
#define PI              2*acos(0.0)
#define rep(i,a,b)      for(ll i=a; i<=b; i++)
#define rev(i,a,b)      for(ll i=a; i>=b; i--)
#define file             #define file            freopen("E:\\file.txt", "r", stdin);ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;

///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------

long long BigMod(long long int a, long long int b, int M)   /// a function to determine a^b(mod M)
{
    long long remainder, answer = 1;                            /// set two variables for remainder and answer
    remainder = a%M;                                         /// setting remainder as
    while(b!=0)                                                     ///  loop occurs until b is not equal to 0
    {
        if(b%2==1)
            answer = (answer*remainder)%M;                  /// checking if b is odd
        /// taking the present remainder in the answer if b is odd
        remainder = (remainder*remainder)%M;    /// making remainder double on each turn of the loop
        b/=2;                                  /// reducing b by dividing it by 2 in every turn,
    }
    return answer;
}
bool cmp(int a,int b)
{
    return a>b;
}
#define mzzz  100005
int parent[mzzz] , hgst = 0,node1,node2,u,cnt;
vector <int > v[mzzz] ;   //Vector for maintaining adjacency list explained above
vector<pair<int, int > >  bal;
map < pair <int,int> , int > ans; //To determine the level of each node
bool vis[mzzz]; //Mark the node if visited
void bfs(int s)
{
    queue <int> q;
    q.push(s);
    vis[ s ] = true;
    while(!q.empty())
    {
        int p = q.front();
        q.pop();
        cnt = 1;
            //cout<<" p -> " << p  << " ";
        for(int i = 0; i < v[ p ].size() ; i++)
        {
            node1 = p;
            node2 = v[p][i];
            u = node2;
            if(node1>node2) swap(node1,node2);
            if(vis[ u ] == false)
            {
                if(cnt==parent[p])cnt++;
                if(hgst<cnt)hgst = cnt;
            //cout << " u -> " << u << " "  << " cnt -> "<<cnt;
                parent[u] = cnt;
                ans[mp(node1,node2)] = cnt++;
                q.push(u);
                vis[ u ] = true;
            }
        }//NL;
    }
}
int main()
{
    int n, x, y;
    scin(n);
    for(int i=1;i<n;i++)
    {
        scin(x);scin(y);

        if(x>y)swap(x,y);
        v[x].pb(y);
        v[y].pb(x);
        bal.pb(mp(x,y));
        ans[mp(x,y)] = 0;
    }
    bfs(1);
    pf("%d\n", hgst);
    //for(int i=1;i<=n;i++)cout << parent[i] << " ";NL;
    for(int i=0;i<bal.size();i++)
    {
        pf("%d\n",ans[bal[i]] );
    }
    return 0;
}


Measured memory_bytes: 13556