#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  int edges;
  scanf("%d", &edges);
  int a[110000], b[110000], d[110000];
  for (int i = 1; i < edges; i++) {
    scanf("%d", &a[i]);
    scanf("%d", &b[i]);
    d[a[i]]++;
    d[b[i]]++;
  }
  int pos = 0;
  for (int i = 1; i < edges; i++) {
    if (d[i] >= 3) pos = i;
  }
  cout << pos << endl;
  int l = 0, p = edges - 1;
  for (int i = 1; i < edges; i++) {
    if (a[i] == pos || b[i] == pos) {
      printf("%d\n", l++);
    } else {
      printf("%d\n", p--);
    }
  }
  return 0;
}
