import std.stdio, std.string, std.algorithm, std.array, std.range, std.conv,
    std.typecons, std.math, std.container, std.format;

void main(string[] args)
{
    long n = readln.strip.to!long;
    alias T = Tuple!(int, int);
    T[] order = [];
    int[][] graph = new int[][](n);
    int[][] edges = new int[][](n, n);
    foreach (i; 0 .. n - 1)
    {
        int a, b;
        readf("%d %d\n", &a, &b);
        graph[a - 1] ~= b - 1;
        graph[b - 1] ~= a - 1;
        order ~= T(a - 1, b - 1);
    }

    int[] queue = [0];
    int[int] visited;
    int max_c = -1;
    while (queue.length != 0)
    {
        int from = queue.front;
        queue.popFront();
        int c = 1;
        foreach (to; graph[from])
        {
            if (to in visited)
            {
                continue;
            }
            edges[from][to] = c;
            edges[to][from] = c++;
            queue ~= to;
            visited[to] = 1;
        }
        max_c = max(max_c, c - 1);
    }

    writeln(max_c);
    foreach (a; order)
    {
        writeln(edges[a[0]][a[1]]);
    }
}
