#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <numeric>

template <typename WeightType>
class weighted_edge {
public:
  using size_type = size_t;
  using weight_type = WeightType;

protected:
  size_type M_src, M_dst;
  weight_type M_weight;

public:
  weighted_edge() = default;
  weighted_edge(weighted_edge const&) = default;
  weighted_edge(weighted_edge&&) = default;

  weighted_edge(size_type s, size_type d, weight_type w):
    M_src(s), M_dst(d), M_weight(w)
  {}

  weighted_edge& operator =(weighted_edge const&) = default;
  weighted_edge& operator =(weighted_edge&&) = default;

  bool operator <(weighted_edge const& other) const {
    if (M_weight < other.M_weight) return true;
    if (other.M_weight < M_weight) return false;
    if (M_src != other.M_src) return M_src < other.M_src;
    return M_dst < other.M_dst;
  }

  size_type source() const { return M_src; }
  size_type target() const { return M_dst; }
  weight_type weight() const { return M_weight; }
};

struct directed_tag {};
struct undirected_tag {};

template <typename Edge, typename Directedness>
class adjacency_list {
public:
  using size_type = size_t;
  using edge_type = Edge;
  using weight_type = typename Edge::weight_type;
  static constexpr weight_type inf = std::numeric_limits<weight_type>::max();

private:
  std::vector<std::vector<edge_type>> M_g;

public:
  adjacency_list() = default;
  adjacency_list(adjacency_list const&) = default;
  adjacency_list(adjacency_list&&) = default;
  adjacency_list(size_type n): M_g(n) {}

  template <typename... Args>
  void emplace(size_type src, size_type dst, Args... args) {
    M_g[src].emplace_back(src, dst, args...);
    if (std::is_same<Directedness, undirected_tag>::value)
      M_g[dst].emplace_back(dst, src, args...);
  }

  void sort_by_index() {
    auto cmp = [](auto const& e1, auto const& e2) {
      return e1.target() < e2.target();
    };
    for (auto v: M_g) std::sort(v.begin(), v.end(), cmp);
  }

  size_type size() const { return M_g.size(); }
  std::vector<edge_type> const& operator [](size_type i) const { return M_g[i]; }
};

template <typename Edge, typename Directedness>
constexpr typename Edge::weight_type inf = adjacency_list<Edge, Directedness>::inf;

void dfs(adjacency_list<weighted_edge<int>, undirected_tag> const& g,
         size_t v, size_t p, std::map<std::pair<size_t, size_t>, int>& res) {

  int ban = -1;
  for (auto const& e: g[v]) {
    if (e.target() == p) {
      size_t s, t;
      std::tie(s, t) = std::minmax(e.source(), e.target());
      ban = res.at(std::make_pair(s, t));
    }
  }
  int color = 1;
  if (color == ban) ++color;
  for (auto const& e: g[v]) {
    size_t u = e.target();
    if (u == p) continue;
    res[std::make_pair(u, v)] = res[std::make_pair(v, u)] = color;
    dfs(g, u, v, res);
    if (++color == ban) ++color;
  }
}

int main() {
  size_t n;
  scanf("%zu", &n);

  adjacency_list<weighted_edge<int>, undirected_tag> g(n);
  std::vector<size_t> deg(n);
  std::vector<std::pair<size_t, size_t>> es(n-1);
  for (size_t i = 1; i < n; ++i) {
    size_t a, b;
    scanf("%zu %zu", &a, &b);
    --a, --b;
    g.emplace(a, b, 1);

    ++deg[a], ++deg[b];
    es[i-1] = std::minmax(a, b);
  }

  size_t v = std::max_element(deg.begin(), deg.end()) - deg.begin();

  std::map<std::pair<size_t, size_t>, int> res;
  dfs(g, v, -1, res);
  printf("%zu\n", deg[v]);
  for (auto const& e: es) {
    printf("%d\n", res.at(e));
  }
}


Measured memory_bytes: 25088