import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

void main()
{
    long N = lread();
    long[long][long] G;
    auto edges = new long[][](N);
    foreach (id; 0 .. N - 1)
    {
        long a, b;
        scan(a, b);
        G[a - 1][b - 1] = (G[b - 1][a - 1] = id);
        edges[a - 1] ~= b - 1;
        edges[b - 1] ~= a - 1;
    }
    auto visited = new bool[](N);
    auto color = new long[](N - 1);
    void dfs(long v, long parent_color)
    {
        if (visited[v])
            return;
        visited[v] = true;
        long c = 1;
        foreach (w; edges[v])
        {
            // writefln("%d %d", v, w);
            long id = G[w][v];
            if (color[id] != 0)
                continue;
            if (c == parent_color)
                c++;
            color[id] = c;
            dfs(w, c);
            c++;
        }
    }

    dfs(0, -1);

    long k = color.reduce!max();
    writeln(k);
    foreach (c; color)
    {
        writeln(c);
    }
}
