using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;

namespace AtCoder
{
    static class Program_D
    {
        class Solver
        {
            int ri => sc.Integer();
            long rl => sc.Long();
            double rd => sc.Double();
            string rs => sc.Scan();
            public StreamScanner sc = new StreamScanner(Console.OpenStandardInput());

            private Edge[] edges;
            private int n;
            private List<Edge>[] nodes;

            //private Dictionary<int,object>[] usedCols;
            private HashSet<int>[] usedCols; 


            // ABC146 Coloring Edges on Tree
            public void Solve()
            {
                LoadEdges();
                //LoadEdgesTestData();
                ConstructNodes();

                var orderInfo = new Tuple<int, int>[n];
                var countInfo = nodes.Select(tmp => tmp.Count).ToArray();
                for (int i = 0; i < n; ++i)
                {
                    orderInfo[i] = Tuple.Create(countInfo[i], i);
                }
                var orderdNodeIndices = orderInfo.OrderByDescending(tmp => tmp.Item1).Select(tmp => tmp.Item2).ToArray();
                //Wl(string.Join(" ",orderdNodeIndices.Select(tmp=>tmp.ToString())));
                int maxColor = 0;
#if true

                long timeSum = 0;
                var swAll = Stopwatch.StartNew();
                for (int i = 0; i < n; ++i)
                {
                    List<Edge> node = nodes[orderdNodeIndices[i]];
                    int color = 0;
                    foreach (var edge in node)
                    {
                        if (edge.Color != 0) continue;
                        color = FindColor(edge, color+1);
                        maxColor = Math.Max(color, maxColor);
                        edge.Color = color;

                        var sw = Stopwatch.StartNew();
                        usedCols[edge.Lhs].Add(color);
                        usedCols[edge.Rhs].Add(color);
                        timeSum += sw.ElapsedMilliseconds;
                    }
                }
                //Wl($"all {swAll.ElapsedMilliseconds}ms, timeSum {timeSum}ms");
#else
                for (int i = 0; i < n-1; ++i)
                {
                    var edge = edges[i];
                    int color = FindColor(edge);
                    maxColor = Math.Max(color, maxColor);
                    edge.Color = color;
                    usedCols[edge.Lhs].Add(color,null);
                    usedCols[edge.Rhs].Add(color,null);
                }
#endif

                Wl(maxColor);
                for (int i = 0; i < n-1; ++i)
                {
                    Wl(edges[i].Color);
                }

            }

            private int FindColor(Edge edge, int from)
            {
                for (int i = from; i <= n; ++i)
                {
                    if (usedCols[edge.Lhs].Contains(i) || usedCols[edge.Rhs].Contains(i)) continue;
                    return i;
                }
                return n;
            }

            private void ConstructNodes()
            {
                nodes = new List<Edge>[n];
                usedCols = new HashSet<int>[n];
                for (int i = 0; i < n; ++i)
                {
                    nodes[i] = new List<Edge>();
                    usedCols[i] = new HashSet<int>();
                }
                for (int i = 0; i < n-1; ++i)
                {
                    var e = edges[i];
                    nodes[e.Lhs].Add(e);
                    nodes[e.Rhs].Add(e);
                }
            }


            private void LoadEdgesTestData()
            {
                n = 20000;
                edges = new Edge[n - 1];
                for (int i = 0; i < n - 1; ++i)
                {
                    edges[i]=new Edge()
                    {
                        Lhs=0,
                        Rhs=i+1,
                        Color=0
                    };
                }
            }
            private void LoadEdges()
            {
                n = ri;
                edges = new Edge[n-1];
                for (int i = 0; i < n-1; ++i)
                {
                    edges[i] = new Edge()
                    {
                        Lhs = ri - 1,
                        Rhs = ri - 1,
                        Color = 0
                    };
                }
            }
            

            // node番号は0-offsetとする.
            class Edge
            {
                public int Lhs;
                public int Rhs;
                public int Color;
            }



            // ----------------------------------------------------------------------------
            static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }


            string Rl()
            {
                return Console.ReadLine();
            }
            void Wl(UInt64 val)
            {
                Console.WriteLine(val);
            }
            void Wl(Int64 val)
            {
                Console.WriteLine(val);
            }
            void Wl(uint val)
            {
                Console.WriteLine(val);
            }
            void Wl(int val)
            {
                Console.WriteLine(val);
            }
            void Wl(double val)
            {
                Console.WriteLine(val);
            }
            void Wl(string mes)
            {
                Console.WriteLine(mes);
            }
            public int Int()
            {
                return int.Parse(Console.ReadLine());
            }

            public int[] Ints(int subtract)
            {
                return Console.ReadLine().Split(' ').Select(s => int.Parse(s) - subtract).ToArray();
            }
            public Int64[] Int64s(Int64 subtract)
            {
                return Console.ReadLine().Split(' ').Select(s => Int64.Parse(s) - subtract).ToArray();
            }
            public UInt64[] UInt64s(UInt64 subtract)
            {
                return Console.ReadLine().Split(' ').Select(s => UInt64.Parse(s) - subtract).ToArray();
            }


        }



        static void Main(string[] args)
        {
            //Console.SetOut(new Printer(Console.OpenStandardOutput()) { AutoFlush = false });
            new Solver().Solve();
            //Console.Out.Flush();
        }
    }

    public class Printer : StreamWriter
    {
        public override IFormatProvider FormatProvider => CultureInfo.InvariantCulture;
        public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
    }

    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }

        public readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;

        private byte read()
        {
            if (isEof) return 0;
            if (ptr >= len)
            {
                ptr = 0;
                if ((len = str.Read(buf, 0, 1024)) <= 0)
                {
                    isEof = true;
                    return 0;
                }
            }
            return buf[ptr++];
        }

        public char Char()
        {
            byte b = 0;
            do b = read(); while ((b < 33 || 126 < b) && !isEof);
            return (char)b;
        }
        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read()) sb.Append(b);
            return sb.ToString();
        }
        public string ScanLine()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b != '\n' && b != 0; b = (char)read()) if (b != '\r') sb.Append(b);
            return sb.ToString();
        }
        public long Long() { return isEof ? long.MinValue : long.Parse(Scan()); }
        public int Integer() { return isEof ? int.MinValue : int.Parse(Scan()); }
        public double Double() { return isEof ? double.NaN : double.Parse(Scan(), CultureInfo.InvariantCulture); }
    }

    struct ModInt
    {
        const int MOD = 1000000007;
        long Data;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public ModInt(long data) { if ((Data = data % MOD) < 0) Data += MOD; }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static implicit operator long(ModInt modInt) => modInt.Data;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static implicit operator ModInt(long val) => new ModInt(val);
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static ModInt operator +(ModInt a, ModInt b)
        {
            long res = a.Data + b.Data;
            return new ModInt() { Data = res >= MOD ? res - MOD : res };
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static ModInt operator +(ModInt a, long b) => a.Data + b;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static ModInt operator -(ModInt a, ModInt b)
        {
            long res = a.Data - b.Data;
            return new ModInt() { Data = res < 0 ? res + MOD : res };
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static ModInt operator -(ModInt a, long b) => a.Data - b;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static ModInt operator *(ModInt a, ModInt b) => new ModInt() { Data = a.Data * b.Data % MOD };
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static ModInt operator /(ModInt a, ModInt b) => a.Data * GetInverse(b);

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override string ToString() => Data.ToString();

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static long GetInverse(long a)
        {
            long div;
            long p = MOD;
            long x1 = 1, y1 = 0, x2 = 0, y2 = 1;
            while (true)
            {
                if (p == 1) return x2;
                div = a / p;
                x1 -= x2 * div;
                y1 -= y2 * div;
                a %= p;
                if (a == 1) return x1;
                div = p / a;
                x2 -= x1 * div;
                y2 -= y1 * div;
                p %= a;
            }
        }
    }

}

Measured memory_bytes: 72732