import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

alias Edge = Tuple!(int, "to", int, "idx");

void main() {
    int N;
    scan(N);
    auto ans = new int[](N - 1);
    ans[] = -1;
    auto adj = new Edge[][](N, 0);
    foreach (i ; 0 .. N - 1) {
        int ai, bi;
        scan(ai, bi);
        ai--, bi--;
        adj[ai] ~= Edge(bi, i);
        adj[bi] ~= Edge(ai, i);
    }

    int K = 0;
    void dfs(int v, int p, int pc) {
        int col = 1;
        foreach (e ; adj[v]) if (e.to != p) {
            if (col == pc) col++;
            ans[e.idx] = col;
            K = max(K, col);
            dfs(e.to, v, col);
            col++;
        }
    }

    dfs(0, -1, -1);

    writeln(K);
    ans.each!(ansi => writeln(ansi));
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}
