#include <bits/stdc++.h>
using namespace std;
int N, mx;
vector<vector<int> > adj;
vector<pair<int, int> > ans;
void dfs(int u, int parent, int now) {
  int tmp = now, out = adj[u].size() - (u != 1);
  ans.push_back({u, now});
  for (int v : adj[u]) {
    if (v == parent) continue;
    if (now == mx) {
      now = mx - out - 1;
      ans.push_back({u, now});
    }
    now++;
    dfs(v, u, now);
    ans.push_back({u, now});
  }
  if (u != 1 && now != tmp - 1) ans.push_back({u, tmp - 1});
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N;
  adj.assign(N + 1, vector<int>());
  int u, v;
  mx = -1e9;
  for (int i = 0; i < N - 1; i++) {
    cin >> u >> v;
    adj[u].push_back(v), adj[v].push_back(u);
    mx = max({mx, (int)adj[u].size(), (int)adj[v].size()});
  };
  dfs(1, -1, 0);
  cout << (int)ans.size() << "\n";
  for (const auto &e : ans) cout << e.first << " " << e.second << "\n";
  return 0;
}
