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 Rust (1.15.1) (judge verdict: Wrong Answer)

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

const INF: usize = 1 << 30;

fn fold(pool: &[usize], x: usize) -> usize {
    assert_eq!(pool.len() % 2, 0);
    let n = pool.len();
    for i in 0..n / 2 {
        if pool[n - i - 1] + pool[i] > x {
            return INF;
        }
    }
    0
}

fn opt(pool: &[usize], x: usize) -> usize {
    let n = pool.len();
    assert_eq!(n % 2, 1);
    let mut pass = n as i32;
    let mut fail = -1;
    while pass - fail > 1 {
        let mid = (pass + fail) / 2;
        let idx = mid as usize;
        let mut ok = true;
        for i in 0..n / 2 {
            let a = if idx <= i { i + 1 } else { i };
            let b = if idx <= n - i - 2 { n - i - 1 } else { n - i - 1 };
            if pool[a] + pool[b] > x {
                ok = false;
                break;
            }
        }
        if ok {
            pass = mid;
        } else {
            fail = mid;
        }
    }
    if pass < n as i32 {
        pool[pass as usize]
    } else {
        INF
    }
}

fn dfs(v: usize, par: usize, g: &[Vec<usize>], x: usize) -> usize {
    let n = g.len();
    let mut pool = vec![];
    if n == par {
        // Only one child
        let ch = g[v][0];
        let dep = dfs(ch, v, g, x);
        return dep + 1;
    }
    for &w in &g[v] {
        if w == par { continue; }
        let sub = dfs(w, v, g, x);
        pool.push(sub + 1);
    }
    if pool.len() == 0 {
        return 0;
    }
    pool.sort();
    let mut mi = INF;
    if pool.len() % 2 == 0 {
        if pool[pool.len() - 1] > x {
            return x + 1;
        }
        mi = opt(&pool[..pool.len() - 1], x);
        mi = min(mi, fold(&pool, x));
    } else {
        mi = min(mi, opt(&pool, x));
    }
    mi
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        uv: [(usize1, usize1); n - 1],
    }
    let mut g = vec![vec![]; n];
    for &(a, b) in &uv {
        g[a].push(b);
        g[b].push(a);
    }
    let mut a = 1;
    for i in 0..n {
        let d = g[i].len();
        if d >= 3 {
            a += (d - 1) / 2;
        }
    }
    let mut r = 0;
    for i in 0..n {
        if g[i].len() == 1 {
            r = i;
            break;
        }
    }
    // Find the smallest b by binsect.
    let mut pass = n - 1;
    let mut fail = 0;
    while pass - fail > 1 {
        let mid = (pass + fail) / 2;
        let res = dfs(r, n, &g, mid);
        if res <= mid {
            pass = mid;
        } else {
            fail = mid;
        }
    }
    puts!("{} {}\n", a, pass);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}