#include<bits/stdc++.h>
using namespace std;
/**
********************************************************************
******************* Author:Bisnu sarkar ****************************
********************************************************************
**/
#define ull            unsigned long long
#define ll             long long
#define vi             vector<int>
#define pb             push_back
#define mp             make_pair
#define pii            pair<int,int>
#define vit            vector<int> :: iterator
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*/
#define error(args...) {vector <string> _v = split(#args, ','); err(_v.begin(), args); cout << endl;}
vector <string> split(const string &s, char c) {
    vector <string> v;
    stringstream ss(s); string x;
    while (getline(ss, x, c)) v.emplace_back(x);
    return move(v);
}
void err(vector <string> :: iterator it) {}
template <typename T, typename... Args>
void err(vector <string> :: iterator it, T a, Args... args) {
    cout << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", ";
    err(++it, args...);
}
 
int ini(){int x; scanf("%d",&x);return x;}
long long inl(){ long long x;scanf("%lld",&x); return x;}
double ind(){double x; scanf("%lf",&x);return x;}
#define Iin ini();
#define Lin inl();
#define Din ind();

int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;

int deg[N],k,edge_col[N],node_col[N];
bool vis[N];
std::vector<pii> adj[N];

void bfs(int u){
    vis[u]=true;
    queue<int>q;

    q.push(u);
    vis[u]=true;

    while(!q.empty()){
        int u=q.front();
      //  printf("%d\n", u);
        q.pop();
        int c=1;
        for(int i=0;i<adj[u].size();++i){
            int v=adj[u][i].ff;
            
            if(!vis[v]){
                if(node_col[u]==c){
                    c++;
                }
                edge_col[adj[u][i].ss]=c;
                node_col[v]=c;
                c++;
                vis[v]=true;
                q.push(v);
            }
        }


    }
}

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
    int t=1,te=0;
 
    while(t--){
        int n;
        cin>>n;
        int ans=0;
        for(int i=1;i<n;i++){
            int u,v;
            cin>>u>>v;
            adj[u].push_back({v,i});
            adj[v].push_back({u,i});

            deg[u]++;
            deg[v]++;
            if(deg[u]>deg[ans]){
                ans=u;
            }

            if(deg[v]>deg[ans]){
                ans=v;
            }
        }
        k=deg[ans];

        bfs(ans);

        printf("%d\n", deg[ans]);

        for(int i=1;i<n;i++){
            printf("%d\n", edge_col[i]);
        }

        //printf("Case %d: ",++te);
    }
    return 0;
}




Measured memory_bytes: 36992