import std.stdio;
import std.string;
import std.algorithm;

void main() {
  int n;
  readf(" %d", &n);
  int[] a = new int[n - 1];
  int[] b = new int[n - 1];
  int[][] g = new int[][n];
  foreach (i; 0..n-1) {
    readf(" %d %d", &a[i], &b[i]);
    a[i]--;
    b[i]--;
    g[a[i]] ~= i;
    g[b[i]] ~= i;
  }
  int d = 0;
  foreach (i; 0..n) d = max(d, cast(int)g[i].length);
  int[] ans = new int[n - 1];
  void dfs(int u, int p, int c) {
    foreach (i; g[u]) {
      int v = u ^ a[i] ^ b[i];
      if (v == p) continue;
      ans[i] = c;
      c = (c + 1) % d;
      dfs(v, u, c);
    }
  }
  dfs(0, -1, 0);
  writeln(d);
  foreach (i; 0..n-1) {
    writeln(ans[i] + 1);
  }
}
