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

ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias t = Tuple!(string, "name", long, "y");

void main()
{
    auto n = lread();
    auto tree = new long[][][](n, 0, 0);
    auto node = new long[][](n - 1, 0);
    foreach (i; iota(n - 1))
    {
        long a, b;
        scan(a, b);
        a--, b--;
        tree[a] ~= [b, 0];
        tree[b] ~= [a, 0];
        node[i] = [a, b, tree[a].length - 1];
    }
    long k;
    tree.each!(x => k = max(x.length, k));
    k.writeln();
    foreach (i; iota(n))
    {
        if (i == 0)
        {
            foreach (j; iota(tree[i].length))
            {
                auto child = tree[i][j][0];
                tree[i][j][1] = j + 1;
                tree[child][0][1] = j + 1;
            }
            continue;
        }
        auto parent = tree[i][0][1];
        bool flag;
        foreach (j; iota(1, tree[i].length))
        {
            if (j == parent)
                flag = true;

            auto child = tree[i][j][0];
            if (flag)
            {
                tree[i][j][1] = j + 1;
                tree[child][0][1] = j + 1;
            }
            else
            {
                tree[i][j][1] = j;
                tree[child][0][1] = j;
            }
        }
    }
    // tree.writeln();
    foreach(e; node)
    {
        tree[e[0]][e[2]][1].writeln();
    }
}

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;
    }
}
