#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <algorithm>
#include <iostream>
#include <bitset>
#include <vector>
#include <array>
using namespace std;
#define f(x,y,z) for(int x=y;x<=z;++x)
vector<int> v[200001];
int n, a, b, it;
array<int, 200001> jr, dlm, nmr;
bitset<200001> sdh;
void jrk(int x) {
    for(int &i:v[x]) if(!jr[i]) {
        jr[i] = jr[x]+1, jrk(i);
    }
}
void trn(int x) {
    sdh[x] = true;
    for(int &i:v[x]) if(!sdh[i]) {
        trn(i), dlm[x] = max(dlm[x], dlm[i]+1);
    }
}
void isi(int x) {
    sdh[x] = true, nmr[x] = a;
    vector<pair<int, int>> mn;
    for(int &i:v[x]) if(!sdh[i]) mn.push_back({dlm[i], i});
    sort(mn.begin(), mn.end());
    for(auto &i:mn) ++a, isi(i.second), ++a;
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n;
    f(i,2,n) {
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    jr[1] = a = 1, jrk(1);
    it = max_element(jr.begin()+1, jr.begin()+n+1)-jr.begin();
    trn(it), sdh.reset(), isi(it);
    f(i,1,n) cout << nmr[i] << ' ';
}
#include <iostream>

using namespace std;

const int N = 400'009;

int p[N];

int find(int x) {
  if (p[x] != x) {
    p[x] = find(p[x]);
  }
  return p[x];
}

int sz[N];
int cycle[N];

int main() {
#ifndef LOCAL
  cin.tie(0);
#endif
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < N; ++i) {
    p[i] = i;
    sz[i] = 1;
    cycle[i] = 0;
  }
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> y >> x;
    --x;
    --y;
    int px = find(x);
    int py = find(y);
    if (py != px) {
      p[py] = px;
      sz[px] += sz[py];
      if (cycle[py]) {
        cycle[px] = 1;
      }
    } else {
      cycle[px] = 1;
    }
  }
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    if (find(i) == i) {
      ans += sz[i] - 1 + cycle[i];
    }
  }
  cout << ans << '\n';
}
