/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/* libnum {{{*/
void amax(N, Args...)(ref N x, Args y) {
  x = x.max(y);
}
void amin(N, Args...)(ref N x, Args y) {
  x = x.min(y);
}
auto maxE(R)(R r) if (isInputRange!R) {
  ElementType!R x = r.front;
  r.popFront();
  foreach (y; r) x.amax(y);
  return x;
}
auto minE(R)(R r) if (isInputRange!R) {
  ElementType!R x = r.front;
  r.popFront();
  foreach (y; r) x.amin(y);
  return x;
}
/*}}}*/

/+---test
3
1 2
2 3
---+/
/+---test
8
1 2
2 3
2 4
2 5
4 7
5 6
6 8
---+/
/+---test
6
1 2
1 3
1 4
1 5
1 6
---+/

void main(string[] args) {
  const N = readln.chomp.to!long;

  struct Edge { long to, i; }

  Edge[][] edges;
  edges.length = N;

  foreach (i; 0..N-1) {
    long a, b;
    readf(" %d %d ", &a, &b);
    --a;
    --b;

    edges[a] ~= Edge(b, i);
    edges[b] ~= Edge(a, i);
  }

  auto ans  = new long[N-1];
  auto seen = new bool[N];

  long colors;

  void rec(long target, long next_col) {
    if (seen[target]) return;
    seen[target] = true;

    foreach (e; edges[target]) {
      if (ans[e.i] != 0) continue;
      ans[e.i] = next_col;
      colors.amax(next_col);
      rec(e.to, next_col+1);
      ++next_col;
    }
  }
  rec(0, 1);
  colors.writeln;
  ans.each!writeln;
}
