/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */

#include <bits/stdc++.h>
//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}


#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;

template<typename T>
class VectorVectorBaseGraph {
public:
    using Edge = T;
    using Vertex = std::size_t;

    explicit VectorVectorBaseGraph(std::size_t n) : g(n) {
    }

    template<typename U>
    using Collection = std::vector<U>;

    template<typename U>
    Collection<U> getCollection(const U &defaultValue) const {
        return Collection<U>(g.size(), defaultValue);
    }

    std::vector<std::size_t> vertices() const {
        std::vector<std::size_t> order(g.size());
        std::iota(order.begin(), order.end(), 0);
        return order;
    }

    const std::vector<Edge> &outgoingEdges(Vertex vertex) const {
        return g[vertex];
    }

    vector<Vertex> toposort() {
        int n = g.size();
        vector<bool> used(n);
        vector<Vertex> order;
        for (int i = 0; i < n; i++)
            if (!used[i])
                dfs(used, order, i);
        reverse(order.begin(), order.end());
        return order;
    }

    virtual Vertex endOfEdge(Vertex, Edge) const = 0;

protected:
    std::vector<std::vector<Edge>> g;

private:
    void dfs(vector<bool> &used, vector<Vertex> &order, int u) {
        used[u] = true;
        for (Edge ed : outgoingEdges(u)) {
            Vertex v = endOfEdge(u, ed);
            if (!used[v])
                dfs(used, order, v);
        }
        order.push_back(u);
    }
};


class SimpleGraph : public VectorVectorBaseGraph<std::size_t> {
public:
    explicit SimpleGraph(std::size_t n) : VectorVectorBaseGraph(n) {}

    Vertex endOfEdge(Vertex, Edge edge) const {
        return edge;
    }

    void addEdge(Vertex from, Vertex to) {
        g[from].push_back(to);
    }
};


template<typename T>
class WeightedGraph : public VectorVectorBaseGraph<std::pair<std::size_t, T>> {
    using Base = VectorVectorBaseGraph<std::pair<std::size_t, T>>;
public:
    using Length = T;
    using Vertex = typename Base::Vertex;
    using Edge = typename Base::Edge;
    using Base::g;

    explicit WeightedGraph(std::size_t n) : Base(n) {}

    Vertex endOfEdge(Vertex, Edge edge) const {
        return edge.first;
    }

    void addEdge(Vertex from, Vertex to, const Length &l) {
        g[from].emplace_back(to, l);
    }

    Length edgeLength(Vertex, const Edge &e) const {
        return e.second;
    }
};


using namespace std;

class DColoringEdgesOnTree {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n;
        in >> n;
        WeightedGraph<int> graph(n);
        for (int i = 0; i < n - 1; ++i) {
            int u, v;
            in >> u >> v;
            --u, --v;
            graph.addEdge(u, v, i);
            graph.addEdge(v, u, i);
        }
        vector<int> color(n - 1);

        function<void(int, int)> dfs = [&](int u, int c) {
            int nc = 1;
            for (auto ed: graph.outgoingEdges(u)) {
                int v = graph.endOfEdge(u, ed), id = graph.edgeLength(u, ed);
                if (not color[id]) {
                    color[id] = nc == c ? ++nc : nc;
                    dfs(v, color[id]);
                    ++nc;
                }
            }
        };

        dfs(0, 0);
        int res = *max_element(color.begin(), color.end());
        out << res << "\n";
        for (int c: color) {
            out << c << "\n";
        }
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    DColoringEdgesOnTree solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 10496