#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  int u[n - 1], v[n - 1];
  map<int, int> deg;
  for (int i = 0; i < n - 1; i++) {
    cin >> u[i] >> v[i];
    deg[u[i]]++;
    deg[v[i]]++;
  }
  int notLeaf = 0;
  for (int i = 1; i <= n; i++) {
    if (deg[i] == 1) {
      notLeaf++;
    }
  }
  int leaf = 0;
  for (int i = 0; i < n - 1; i++) {
    if (deg[u[i]] == 1 || deg[v[i]] == 1) {
      cout << leaf << "\n";
      leaf++;
    } else {
      cout << notLeaf << "\n";
      notLeaf++;
    }
  }
  return 0;
}
