using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    partial class Program
    {
        static long mod = 1000000007;
        static void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; }
        static void Main()
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Console.Out.Flush();
            Console.ReadKey();
        }

        //ここから

        static void Solve()
        {
            int N = GetInt();
            List<int>[] A = Enumerable.Repeat(0, N).Select(s => new List<int>()).ToArray();
            var G = new Tuple<int, int>[N - 1];
            var color = new Dictionary<Tuple<int, int>, int>();
            for(int i = 0; i < N -1 ; i++)
            {
                var cin = GetIntArray().Select(s => s - 1).ToArray();
                G[i] = new Tuple<int, int>(cin[0], cin[1]);
                A[cin[0]].Add(cin[1]);
                A[cin[1]].Add(cin[0]);
                color.Add(new Tuple<int, int>(cin[0], cin[1]), -1);
                color.Add(new Tuple<int, int>(cin[1], cin[0]), -1);
            }

            var next = new Queue<int>();
            next.Enqueue(A[0].First());
            var parcol = new int[N];

            color[new Tuple<int, int>(0, A[0].First())] = 1;
            var K = 0;
            while (next.Count > 0)
            {
                var n = next.Dequeue();
                var pc = parcol[n];
                var k = 1;
                foreach(var a in A[n])
                {
                    if (color[new Tuple<int, int>(n,a)] != -1) continue;
                    if (pc == k) k++;
                    K = Math.Max(k, K);
                    next.Enqueue(a);
                    parcol[a] = k;
                    color[new Tuple<int, int>(a, n)] = k;
                    color[new Tuple<int, int>(n, a)] = k;
                    k++;
                }
            }
            Console.WriteLine(K);
            G.Select(s => color[new Tuple<int, int>(s.Item1, s.Item2)]).ToList().ForEach(i => Console.WriteLine(i));

            //Console.WriteLine(ans);

        }
    }

    //拡張メソッド
    public static class Ex
    {
        public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); }
        public static string yesno(this bool b) { return b ? "yes" : "no"; }
        public static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        public static string YESNO(this bool b) { return b ? "YES" : "NO"; }
    }

    partial class Program
    {
        static public string GetStr() { return Console.ReadLine().Trim(); }
        static public char GetChar() { return Console.ReadLine().Trim()[0]; }
        static public int GetInt() { return int.Parse(Console.ReadLine().Trim()); }
        static public long GetLong() { return long.Parse(Console.ReadLine().Trim()); }
        static public double GetDouble() { return double.Parse(Console.ReadLine().Trim()); }
        static public string[] GetStrArray() { return Console.ReadLine().Trim().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray(); }
        static public char[] GetCharArray() { return Console.ReadLine().Trim().Split(' ').Select(char.Parse).ToArray(); }
        static public double[] GetDoubleArray() { return Console.ReadLine().Trim().Split(' ').Select(double.Parse).ToArray(); }
        static public void WriteObjects<T>(IList<T> values) { var num = values.Count; for (int i = 0; i < num; i++) { Console.Write(values[i]); if (i < num - 1) { Console.Write(" "); } } Console.WriteLine(); }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
        static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]);
        }
        static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]);
        }
    }
}


Measured memory_bytes: 45516