Problem:
Score : 900 points

Problem Statement

Takahashi has decided to make a Christmas Tree for the Christmas party in AtCoder, Inc.

A Christmas Tree is a tree with N vertices numbered 1 through N and N-1 edges, whose i-th edge (1\leq i\leq N-1) connects Vertex a_i and b_i.

He would like to make one as follows:

Specify two non-negative integers A and B.

Prepare A Christmas Paths whose lengths are at most B. Here, a Christmas Path of length X is a graph with X+1 vertices and X edges such that, if we properly number the vertices 1 through X+1, the i-th edge (1\leq i\leq X) will connect Vertex i and i+1.

Repeat the following operation until he has one connected tree:

Select two vertices x and y that belong to different connected components. Combine x and y into one vertex. More precisely, for each edge (p,y) incident to the vertex y, add the edge (p,x). Then, delete the vertex y and all the edges incident to y.

Properly number the vertices in the tree.

Takahashi would like to find the lexicographically smallest pair (A,B) such that he can make a Christmas Tree, that is, find the smallest A, and find the smallest B under the condition that A is minimized.

Solve this problem for him.

Constraints

2 \leq N \leq 10^5

1 \leq a_i,b_i \leq N

The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
a_1 b_1
:
a_{N-1} b_{N-1}

Output

For the lexicographically smallest (A,B), print A and B with a space in between.

Sample Input 1

7
1 2
2 3
2 4
4 5
4 6
6 7

Sample Output 1

3 2

We can make a Christmas Tree as shown in the figure below:

Sample Input 2

8
1 2
2 3
3 4
4 5
5 6
5 7
5 8

Sample Output 2

2 5

Sample Input 3

10
1 2
2 3
3 4
2 5
6 5
6 7
7 8
5 9
10 5

Sample Output 3

3 4

Solution in C# (Mono 4.6.2.0) (judge verdict: Time Limit Exceeded)

using System;
using System.Linq;
using System.Collections.Generic;
using Debug = System.Diagnostics.Trace;
using SB = System.Text.StringBuilder;
using System.Numerics;
using static System.Math;
using Number = System.Int64;
namespace Program {
    public class Solver {
        Random rnd = new Random(0);
        int n;
        List<int>[] G;
        int need;
        void solve() {
            var l = 0; var r = n;
            while (r - l > 1) {
                var m = (l + r) / 2;
                Debug.WriteLine($"try {m}");
                if (f(m)) r = m;
                else l = m;
            }
            Console.WriteLine($"{need} {r}");
        }
        bool g(List<int> a, int k, int x) {
            var cnt = a.Count / 2;
            for (int i = 0, j = a.Count - 1; cnt > 0; i++, j--, cnt--) {
                if (i == k) i++;
                if (j == k) j--;
                if (a[i] + a[j] > x) return false;
            }
            return true;
        }
        Func<int, bool> f;
        public void Solve() {
            n = ri;
            G = Enumerate(n, x => new List<int>());
            foreach (var i in Rep(n - 1)) {
                var u = ri - 1;
                var v = ri - 1;
                G[u].Add(v);
                G[v].Add(u);
            }
            var root = Enumerable.Range(0, n).First(x => G[x].Count == 1);
            need = 1;
            foreach (var i in Rep(n))
                need += (Math.Max(0, G[i].Count - 2) + 1) / 2;

            Debug.WriteLine($"root: {root}");
            f = x => {
                Func<int, int, int> dfs = null;
                var ok = true;
                dfs = (prev, cur) => {
                    var v = new List<int>();
                    foreach (var t in G[cur]) {
                        if (t != prev) v.Add(dfs(cur, t) + 1);
                    }
                    v.Sort();
                    Debug.WriteLine($"{cur}: {v.AsJoinedString()}");
                    if (v.Count % 2 == 0) {
                        var flag = true;
                        for (int i = 0, j = v.Count - 1; i < j; i++, j--)
                            flag &= v[i] + v[j] <= x;
                        if (flag) return 0;
                        else {
                            ok &= v[v.Count - 1] <= x;
                            v.RemoveAt(v.Count - 1);
                        }
                    }
                    if (!g(v, v.Count - 1, x)) { ok = false; return 0; }
                    var l = -1; var r = v.Count - 1;
                    while (r - l > 1) {
                        var m = (l + r) / 2;
                        if (g(v, m, x)) r = m;
                        else l = m;

                    }
                    return v[r];
                };
                return dfs(-1, root) <= x && ok;
            };

            solve();

        }
        const long INF = 1L << 60;
        int ri => sc.Integer();
        long rl => sc.Long();
        double rd => sc.Double();
        string rs => sc.Scan();
        public IO.StreamScanner sc = new IO.StreamScanner(Console.OpenStandardInput());

        static IEnumerable<int> Rep(int n) => Enumerable.Range(0, n);
        static IEnumerable<int> RRep(int n) => Enumerable.Range(0, n).Reverse();
        static T[] Enumerate<T>(int n, Func<int, T> f) {
            var a = new T[n];
            for (int i = 0; i < a.Length; ++i) a[i] = f(i);
            return a;
        }
        static public void Swap<T>(ref T a, ref T b) { var tmp = a; a = b; b = tmp; }
    }
}
#region main
static class Ex {
    static public string AsString(this IEnumerable<char> ie) { return new string(ie.ToArray()); }
    static public string AsJoinedString<T>(this IEnumerable<T> ie, string st = " ") {
        return string.Join(st, ie);
    }
    static public void Main() {
        Console.SetOut(new Program.IO.Printer(Console.OpenStandardOutput()) { AutoFlush = true });
        var solver = new Program.Solver();
        solver.Solve();
        Console.Out.Flush();
    }
}
#endregion
#region Ex
namespace Program.IO {
    using System.IO;
    using System.Text;
    using System.Globalization;

    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); }
    }
}

#endregion