#include <bits/stdc++.h>
using namespace std;
int N, a, b;
vector<pair<int, int>> adj[100001];
bool fl[100001];
int l[100001];
int c;
queue<pair<int, int>> q;
pair<int, int> fr;
int main() {
  cin >> N;
  for (int i = 1; i <= N - 1; i++) {
    cin >> a >> b;
    adj[a].push_back({b, i});
    adj[b].push_back({a, i});
    fl[i] = false;
  }
  c = 0;
  for (auto x : adj[1]) {
    q.push(x);
  }
  fl[1] = true;
  while (!q.empty()) {
    fr = q.front();
    fl[fr.first] = true;
    l[fr.second] = c;
    if (c < (N - 2) / 2)
      c = N - 2 - c;
    else
      c++;
    for (auto x : adj[fr.first]) {
      if (!fl[x.first]) {
        q.push(x);
      }
    }
    q.pop();
  }
  for (int i = 1; i <= N - 1; i++) {
    cout << l[i] << endl;
  }
  return 0;
}
