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];
  bool[] seen = new bool[N];

  int paint(int parCol, int node) {
    seen[node] = true;

    int col = 1;
    int m = 0;
    foreach(c; G[node]) {
      if(seen[c]) continue;
      if(col == parCol) col++;
      nc[c] = col;
      m = max(m, paint(col, c));
      col++;
    }
    return max(m, col-1);
  }

  int K = paint(-1, 0);
  K.writeln;
  foreach(i; 1..N) writeln(nc[i]);
}
