import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array,
  std.functional, std.container, std.typecons;

void main() {
  int N = readln.chomp.to!int;
  int[][] G = new int[][N];
  foreach(ref r; G) r = new int[0];
  foreach(i; 0..N-1) {
    auto inp = readln.split.to!(int[]);
    int a = inp[0], b = inp[1];
    G[a-1] ~= b-1;
    G[b-1] ~= a-1;
  }

  int[] nc = new int[N];
  ulong bfs() {
    bool[] seen = new bool[N];
    auto que = DList!int();
    seen[0] = true;
    que.insertBack(0);
    ulong K = 0;

    while(!que.empty()) {
      int v = que.front; que.removeFront();
      seen[v] = true;
      K = max(K, G[v].length);

      int c = 1;
      foreach(u; G[v]) {
        if(seen[u]) continue;
        if(c == nc[v]) c++;
        nc[u] = c;
        c++;
        que.insertBack(u);
      }
    }
    return K;
  }

  nc[0] = 0;
  ulong K = bfs();
  K.writeln;
  foreach(i; 1..N) writeln(nc[i]);
}
