/*
"Won't stop until I'm phenomenal."
- Phenomenal, Eminem
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;

vector<vector<int>> g;
map<pair<int,int>,int> mp;
int maxi;

void dfs(int u, int p, int pc){
    int id = 1;
    for(int v : g[u]){
        if(v==p) continue;
        if(pc==id) id++;
        mp[{min(u,v),max(v,u)}] = id;
        maxi = max(maxi,id);
        dfs(v,u,id);
        id++;
    }
}

int main(){
    Shazam;
    int n; cin>>n;
    g = vector<vector<int>>(n);
    vector<pair<int,int>> e;
    for(int i = 0 ; i < n-1; i++){
        int a, b; cin>>a>>b;
        a--;
        b--;
        e.push_back({min(a,b),max(a,b)});
        g[b].push_back(a);
        g[a].push_back(b);
        maxi = max(maxi,(int) g[a].size());
        maxi = max(maxi,(int) g[b].size());
    }
    dfs(0,0,0);
    cout<<maxi<<endl;
    for(auto p : e){
        cout<<mp[p]<<endl;
    }

    return 0;
}