#include <bits/stdc++.h>

using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  


const int N = 1e5 + 5;

vector<int> tree[N];
vector<int> color[N];
vector<int> ans(N);
vector<bool> vis(N, false);
map<pair<int,int>, int> idx;
map<int, int> m;

void dfs(int node, int prev, int last_color)
{
    if(prev != -1)
    {
        for(int i=0;i<tree[node].size();i++)
        {
            if(tree[node][i] == prev)
            {
                color[node][i] = last_color;
            }
        }
    }
    vis[node] = true;
    set<int> s;
    for(int i=0;i<color[node].size();i++)
    {
        if(color[node][i] != -1)
            s.insert(color[node][i]);
    }
    int curr_color = 1;
    for(int i=0;i<tree[node].size();i++)
    {
        if(vis[tree[node][i]] == true) continue;
        if(color[node][i] == -1)
        {
            while(s.find(curr_color) != s.end()) curr_color++;
            if(s.find(curr_color) == s.end())
            {
                color[node][i] = curr_color;
                s.insert(curr_color);
                dfs(tree[node][i], node, curr_color);
                ans[idx[make_pair(node, tree[node][i])]] = curr_color;
                curr_color++;
            }
        }
    }
}

int32_t main()
{
    fastio;
    int n;
    cin >> n;
    vector<pair<int, int>> v(n-1);
    int max_deg = 0;
    for(int i=0;i<n-1;i++)
    {
        cin >> v[i].first >> v[i].second;
        idx[v[i]] = i;
        idx[{v[i].second, v[i].first}] = i;
        m[v[i].first]++;
        m[v[i].second]++;
        tree[v[i].first].pb(v[i].second);
        tree[v[i].second].pb(v[i].first);
        int dummy = max_deg;
        max_deg = max(max_deg, max(m[v[i].first], m[v[i].second]));
    }
    for(int i=0;i<n;i++)
    {
        color[i+1].resize(tree[i+1].size());
        for(int j=0;j<color[i+1].size();j++) color[i+1][j] = -1;
    }
    cout << max_deg << "\n";
    dfs(1, -1, -1);
    for(int i=0;i<n-1;i++) cout << ans[i] << "\n";
    
    return 0;
}



Measured memory_bytes: 35968