#include <bits/stdc++.h>
using namespace std;
vector<bool> used(100010, 0);
vector<int> ans(100010, -1);
int N;
int K = 1;
vector<pair<int, int>> v[100010];
void paint(int s = 1, int c = 0) {
    used[s] = 1;
    int a = 1;
    for (auto g: v[s]) {
        int t = g.first;
        int n = g.second;
        if (used[t]) continue;
        if (a == c) {
            a++;
        }
        ans[n] = a;
        K = max(K, a);
        paint(t, a);
        a++;
    }
}
int main () {
    cin >> N;
    for (int i = 1; i < N; i++) {
        int a, b;
        cin >> a >> b;
        v[a].push_back(make_pair(b, i));
        v[b].push_back(make_pair(a, i));
    }
    paint();
    cout << K << endl;
    for (int i = 1; i <= N-1; i++) {
        cout << ans[i] << endl;
    }
}