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

alias T = Tuple!(int, int);

void main() {
  int n;
  readf (" %d", &n);
  auto e = new T[][n];
  foreach (k; 0 .. n - 1) {
    int i, j;
    readf (" %d %d", &i, &j);
    --i; --j;
    e[i] ~= tuple (j, k);
    e[j] ~= tuple (i, k);
  }
  auto p = new int[n];
  p[] = -2;
  auto c = new int[n-1];
  void go (int i, int fc) {
    int curc = 0;
    foreach (ref q; e[i]) {
      int j = q[0];
      if (p[j] == -2) {
        p[j] = i;
        ++curc;
        if (curc == fc) ++curc;
        c[q[1]] = curc;
        go (j, curc);
      }
    }
  }
  p[0] = -1;
  go (0, 0);
  int m = 0;
  foreach (i; 0 .. c.length) {
    m = max (m, c[i]);
  }
  writeln (m);
  writefln ("%(%s\n%)", c);

}

