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

void main() {
    auto N = readln.chomp.to!int;
    auto G = new Tuple!(int, int)[][](N);
    foreach (i; 0..N-1) {
        auto s = readln.split.map!(to!int);
        G[s[0]-1] ~= tuple(s[1]-1, i);
        G[s[1]-1] ~= tuple(s[0]-1, i);
    }

    auto ans = new int[](N-1);

    void dfs(int n, int p, int pc) {
        int c = 0;
        foreach (e; G[n]) {
            int m = e[0];
            int idx = e[1];
            if (m == p) continue;
            if (c == pc) c += 1;
            ans[idx] = c + 1;
            dfs(m, n, c);
            c += 1;
        }
    }

    dfs(0, -1, -1);
    G.map!(g => g.length).reduce!max.writeln;
    ans.each!writeln;
}
