You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold:

  For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on the simple path between $v_{1}$ and $v_{2}$ has to be equal to $0$. 

Note that you can put very large positive integers (like $10^{(10^{10})}$).

It's guaranteed that such assignment always exists under given constraints. Now let's define $f$ as the number of distinct weights in assignment.

 [Image] In this example, assignment is valid, because bitwise XOR of all edge weights between every pair of leaves is $0$. $f$ value is $2$ here, because there are $2$ distinct edge weights($4$ and $5$).

[Image] In this example, assignment is invalid, because bitwise XOR of all edge weights between vertex $1$ and vertex $6$ ($3, 4, 5, 4$) is not $0$. 

What are the minimum and the maximum possible values of $f$ for the given tree? Find and print both.


-----Input-----

The first line contains integer $n$ ($3 \le n \le 10^{5}$) — the number of vertices in given tree.

The $i$-th of the next $n-1$ lines contains two integers $a_{i}$ and $b_{i}$ ($1 \le a_{i} \lt b_{i} \le n$) — it means there is an edge between $a_{i}$ and $b_{i}$. It is guaranteed that given graph forms tree of $n$ vertices.


-----Output-----

Print two integers — the minimum and maximum possible value of $f$ can be made from valid assignment of given tree. Note that it's always possible to make an assignment under given constraints.


-----Examples-----
Input
6
1 3
2 3
3 4
4 5
5 6

Output
1 4

Input
6
1 3
2 3
3 4
4 5
4 6

Output
3 3

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

Output
1 6



-----Note-----

In the first example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.  [Image] 

In the second example, possible assignments for each minimum and maximum are described in picture below. The $f$ value of valid assignment of this tree is always $3$.  [Image] 

In the third example, possible assignments for each minimum and maximum are described in picture below. Of course, there are multiple possible assignments for each minimum and maximum.  [Image]

Difficulty: MEDIUM_HARD

Solutions:
import collections
from collections import defaultdict
import sys
input = sys.stdin.readline
n = int(input())
graph = defaultdict(list)
for i in range(n - 1):
	(a, b) = map(int, input().split())
	graph[a].append(b)
	graph[b].append(a)
count = 0
leavepar = [0] * (n + 1)
leave = []
for i in graph:
	if len(graph[i]) == 1:
		leave.append(i)
		leavepar[graph[i][0]] += 1
		if leavepar[graph[i][0]] >= 2:
			count += 1

def bfs(graph, root):
	visited = set()
	dist = [0] * (n + 1)
	queue = collections.deque([root])
	visited.add(root)
	while queue:
		vertex = queue.popleft()
		for neighbour in graph[vertex]:
			if neighbour not in visited:
				dist[neighbour] = dist[vertex] + 1
				visited.add(neighbour)
				queue.append(neighbour)
	return dist
ret = bfs(graph, 1)
ans = 1
(even, odd) = (False, False)
for i in leave:
	if ret[i] % 2 == 1:
		odd = True
	if ret[i] % 2 == 0:
		even = True
	if even == True and odd == True:
		ans = 3
		break
sys.stdout.write(str(ans) + ' ' + str(n - count - 1) + '\n')


import sys
n = int(input())
adj = [[] for _ in range(n)]
for _ in range(n - 1):
	(a, b) = [int(x) for x in sys.stdin.readline().split()]
	a -= 1
	b -= 1
	adj[a].append(b)
	adj[b].append(a)
mx = n - 1
for i in range(n):
	num_adj_leaves = sum([1 for b in adj[i] if len(adj[b]) == 1])
	if num_adj_leaves:
		mx -= num_adj_leaves - 1
root = 0
parent = [None] * n
parent[0] = -1
stack = [0]
toposort = []
while len(stack):
	cur = stack.pop()
	toposort.append(cur)
	for nb in adj[cur]:
		if parent[nb] == None:
			parent[nb] = cur
			stack.append(nb)
toposort = list(reversed(toposort))
has_even_from_leaf = [False] * n
has_odd_from_leaf = [False] * n
for v in toposort:
	if len(adj[v]) == 1:
		has_even_from_leaf[v] = True
	if parent[v] != -1:
		has_even_from_leaf[parent[v]] |= has_odd_from_leaf[v]
		has_odd_from_leaf[parent[v]] |= has_even_from_leaf[v]
mn = 1
if any((has_even_from_leaf[v] and has_odd_from_leaf[v] for v in range(n))):
	mn += 2
print(mn, mx)


import os
import sys
from io import BytesIO, IOBase
from collections import deque

def main():
	n = int(input())
	tree = [[] for _ in range(n + 1)]
	for i in range(n - 1):
		(x, y) = map(int, input().split())
		tree[x].append(y)
		tree[y].append(x)
	(h, v, l, c, q) = ([0] * (n + 1), [0] * (n + 1), [], 0, deque())
	for i in range(1, n + 1):
		if len(tree[i]) > 1:
			q.append(i)
			v[i] = 1
			break
	while q:
		(z, f) = (q.popleft(), 0)
		for i in tree[z]:
			if not v[i]:
				(h[i], v[i]) = (h[z] + 1, 1)
				q.append(i)
				if len(tree[i]) == 1:
					l.append(i)
					f = 1
		if f:
			c += 1
	mi = 1
	for i in range(len(l) - 1):
		if h[l[i]] % 2 != h[l[i + 1]] % 2:
			mi = 3
			break
	print(mi, n - 1 - len(l) + c)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
G = {}
for i in range(n - 1):
	(a, b) = map(int, input().split())
	try:
		G[a].append(b)
	except:
		G[a] = [b]
	try:
		G[b].append(a)
	except:
		G[b] = [a]
leaves = []
for i in G.keys():
	if len(G[i]) == 1:
		leaves.append(i)
	else:
		sv = i
val = [-1 for i in range(n + 1)]
Q = [sv]
val[sv] = 0
tp = 0
while len(Q) != 0:
	a = Q.pop()
	iv = val[a]
	tc = -1
	for i in G[a]:
		if val[i] == -1:
			val[i] = iv + 1
			if len(G[i]) == 1:
				tc = tc + 1
			else:
				Q.append(i)
	tp = tp + max(tc, 0)
v = val[leaves[0]]
flag = 0
for i in range(1, len(leaves)):
	if abs(val[leaves[i]] - v) % 2 != 0:
		flag = 1
		break
if flag == 0:
	print(1, end=' ')
else:
	print(3, end=' ')
print(n - tp - 1)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from collections import deque
n = int(input())
neigh = [[] for i in range(n)]
for i in range(n - 1):
	(u, v) = map(int, input().split())
	neigh[v - 1].append(u - 1)
	neigh[u - 1].append(v - 1)
for i in range(n):
	if len(neigh[i]) == 1:
		root = i
		break
queue = deque()
visited = [False] * n
visited[root] = True
queue.append([root, 0])
leafneigh = {}
maximum = n - 1
odd = 0
even = 0
while queue:
	[index, d] = queue.popleft()
	if len(neigh[index]) == 1:
		if neigh[index][0] not in leafneigh:
			leafneigh[neigh[index][0]] = d
			if d % 2 == 0:
				odd += 1
			else:
				even += 1
		else:
			maximum -= 1
	for ele in neigh[index]:
		if visited[ele]:
			continue
		visited[ele] = True
		queue.append([ele, d + 1])
if min(odd, even) == 0:
	minimum = 1
else:
	minimum = 3
print(minimum, maximum)


from sys import stdin, stderr

def rl():
	return [int(w) for w in stdin.readline().split()]
(n,) = rl()
a = [[] for _ in range(n)]
for _ in range(n - 1):
	(ai, bi) = rl()
	a[ai - 1].append(bi - 1)
	a[bi - 1].append(ai - 1)
for v in range(n):
	if len(a[v]) == 1:
		f = [(v, a[v][0])]
		break
d = 2
f0 = 1
f1 = 0
while f:
	nf = []
	for (u, v) in f:
		df1 = 1
		for w in a[v]:
			if w != u:
				if len(a[w]) > 1:
					nf.append((v, w))
				elif d > 2:
					df1 = 2
					if d % 2:
						f0 = 3
		f1 += df1
	f = nf
	d += 1
print(f0, f1)


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
from bisect import bisect, bisect_left
from time import time
from itertools import permutations as per
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\r\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
lcm = lambda x, y: x * y // gcd(x, y)
nCr = lambda x, y: f[x] * inv(f[y] * f[x - y] % N) % N
inv = lambda x: pow(x, N - 2, N)
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
n = I()
a = [[] for i in range(n + 1)]
dg = [0] * (n + 1)
for i in range(n - 1):
	(x, y) = R()
	a[x] += (y,)
	a[y] += (x,)
	dg[x] += 1
	dg[y] += 1
if n == 2:
	exit(print(1, 1))
mn = 1
mx = n - 1
stk = [a[dg.index(1)][0]]
ch = []
pr = [0] * (n + 1)
z = [1] * (n + 1)
ln = [0] * (n + 1)
val = [0] * (n + 1)
vst = [1] * (n + 1)
vst[stk[0]] = 0
while stk:
	p = stk.pop()
	if dg[p] == 1 and val[p] % 2 == 0:
		mn = 3
	for el in a[p]:
		if vst[el]:
			stk += (el,)
			ch += (el,)
			vst[el] = 0
			pr[el] = p
			val[el] += 1 + val[p]
for i in ch[::-1]:
	if z[i] == 1:
		if ln[pr[i]]:
			mx -= 1
		else:
			ln[pr[i]] = 1
	z[pr[i]] += z[i]
print(mn, mx)


from collections import deque

def readTree(v):
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(v1, v2) = [int(x) for x in input().split()]
		adj[v1].add(v2)
		adj[v2].add(v1)
	return adj

def bfs(adj):
	visited = [True] + [False] * v
	q = deque()
	for i in range(1, v + 1):
		if len(adj[i]) > 1:
			root = i
			break
	q.append(root)
	visited[root] = True
	edges = [0] * (v + 1)
	parent = [0] * (v + 1)
	depth = [0] * (v + 1)
	depth_leaf = deque()
	while q:
		ele = q.pop()
		leaf = False
		for a in adj[ele]:
			if visited[a] == False:
				depth[a] = depth[ele] + 1
				if adj[a] == {ele}:
					if leaf == False:
						edges[ele] += 1
						leaf = True
					depth_leaf.append(depth[a])
				else:
					edges[ele] += 1
				parent[a] = ele
				q.append(a)
				visited[a] = True
	return (edges, depth_leaf)
v = int(input())
adj = readTree(v)
(edges, depth_leaf) = bfs(adj)
for i in range(1, len(depth_leaf)):
	if (depth_leaf[i] + depth_leaf[i - 1]) % 2 != 0:
		minn = 3
		break
else:
	minn = 1
print(minn, sum(edges))


import collections
n1 = input()
n = int(n1)
if n == 2:
	print(1, 1)
	exit()
edges = [set() for _ in range(n)]
for i in range(n - 1):
	x = input()
	(a, b) = x.split(' ')
	(a, b) = (int(a), int(b))
	edges[a - 1].add(b - 1)
	edges[b - 1].add(a - 1)
ocnt = collections.deque()
for i in range(n):
	if len(edges[i]) == 1:
		ocnt.append(i)
nl = set()
for i in ocnt:
	for j in edges[i]:
		nl.add(j)
x = ocnt[0]
(que, l) = (collections.deque([(-1, x)]), 1)
lo = 1
while que:
	size = len(que)
	for _ in range(size):
		(p, top) = que.popleft()
		if len(edges[top]) == 1 and l % 2 == 0:
			lo = 3
			break
		for j in edges[top]:
			if j != p:
				que.append((top, j))
	l += 1
hi = n - len(ocnt) + len(nl) - 1
print(lo, hi)


import math
import sys
from collections import defaultdict, Counter, deque, OrderedDict
import bisect
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]
from itertools import accumulate, groupby
import sys
import heapq
first = 1
G = defaultdict(list)

def addEdge(a, b):
	G[a].append(b)
	G[b].append(a)

def BFSUtil(queue, vis, level):
	while queue:
		s = queue.popleft()
		for child in G.get(s, []):
			if vis[child] == False:
				queue.append(child)
				vis[child] = True
				level[child] = level[s] + 1

def sssp(node, N):
	vis = [False for i in range(N + 1)]
	level = [0 for i in range(N + 1)]
	queue = deque()
	queue.append(node)
	vis[node] = True
	level[node] = 0
	BFSUtil(queue, vis, level)
	return level
N = int(input())
maxi = N - 1
for _ in range(N - 1):
	(u, v) = ilele()
	addEdge(u, v)
if N == 3:
	(maxi, mini) = (1, 1)
else:
	l = {}
	source = None
	for (i, j) in G.items():
		if len(j) == 1:
			l[i] = 1
			source = i
	X = sssp(source, N)
	f = 0
	for i in l.keys():
		if X[i] % 2 != 0:
			f = 1
			break
	nodemark = {}
	for (i, j) in G.items():
		if len(j) == 1:
			if nodemark.get(j[0], -1) == 1:
				maxi -= 1
			else:
				nodemark[j[0]] = 1
	if f == 0:
		mini = 1
	else:
		mini = 3
print(mini, maxi)


import sys
input = sys.stdin.readline
n = int(input())
E = [[] for i in range(n + 1)]
for i in range(n - 1):
	(a, b) = list(map(int, input().split()))
	E[a].append(b)
	E[b].append(a)
LEAF = []
for i in range(n + 1):
	if len(E[i]) == 1:
		LEAF.append(i)
Q = [1]
USE = [-1] * (n + 1)
USE[1] = 0
while Q:
	x = Q.pop()
	for to in E[x]:
		if USE[to] == -1:
			USE[to] = 1 - USE[x]
			Q.append(to)
f = USE[LEAF[0]]
for l in LEAF:
	if f != USE[l]:
		MIN = 3
		break
else:
	MIN = 1
MAX = n - 1
FP = [0] * (n + 1)
for l in LEAF:
	for to in E[l]:
		if FP[to] == 1:
			MAX -= 1
		else:
			FP[to] = 1
print(MIN, MAX)


def solveAll():
	case = readCase()
	print(*solve(case))

def readCase():
	treeSize = int(input())
	graph = [[] for i in range(treeSize)]
	for _ in range(1, treeSize):
		(a, b) = (int(x) for x in input().split())
		a -= 1
		b -= 1
		graph[a] += [b]
		graph[b] += [a]
	return graph

def solve(graph):
	leafs = computeLeafs(graph)
	return (minF(graph, leafs), maxF(graph, leafs))

def computeLeafs(graph):
	leafs = [node for node in range(0, len(graph)) if len(graph[node]) == 1]
	return leafs

def minF(graph, leafs):
	color = [None] * len(graph)
	queue = [0]
	color[0] = 'a'
	head = 0
	while head < len(queue):
		currentNode = queue[head]
		head += 1
		for neighbor in graph[currentNode]:
			if color[neighbor] != None:
				continue
			color[neighbor] = 'b' if color[currentNode] == 'a' else 'a'
			queue += [neighbor]
	if all((color[leafs[0]] == color[leaf] for leaf in leafs)):
		return 1
	return 3

def maxF(graph, leafs):
	group = [0] * len(graph)
	for leaf in leafs:
		parent = graph[leaf][0]
		group[parent] += 1
	ans = len(graph) - 1
	for size in group:
		if size >= 2:
			ans -= size - 1
	return ans
solveAll()


import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
N = int(input())
G = [[] for _ in range(N + 1)]
for i in range(N - 1):
	(u, v) = map(int, input().split())
	G[u].append(v)
	G[v].append(u)
leafs = [i for i in range(1, N + 1) if len(G[i]) == 1]
leafNeibs = set()
for u in leafs:
	for v in G[u]:
		leafNeibs.add(v)
maxv = N - 1 - len(leafs) + len(leafNeibs)
minv = 1
q = [leafs[0]]
dist = [N + 1 for _ in range(N + 1)]
d = 0
dist[leafs[0]] = 0
while q:
	nq = []
	d += 1
	for u in q:
		for v in G[u]:
			if dist[v] == N + 1:
				dist[v] = d
				nq.append(v)
	q = nq
if any([dist[v] % 2 != 0 for v in leafs]):
	minv = 3
print('{} {}'.format(minv, maxv))


n = int(input())
graph = [[] for i in range(n + 1)]
deg = [0] * (n + 1)
for i in range(n - 1):
	(x, y) = map(int, input().split())
	graph[x].append(y)
	graph[y].append(x)
	deg[x] += 1
	deg[y] += 1
root = -1
leavs = []
for i in range(n + 1):
	if deg[i] == 1:
		root = i
		break
for i in range(n + 1):
	if deg[i] == 1:
		leavs.append(i)
stack = []
depth = [0] * (n + 1)
stack.append(root)
visi = set()
visi.add(root)
cnt = 0
gg = 0
nod = graph[root][0]
while len(stack) != 0:
	x = stack.pop()
	fn = 0
	for nodes in graph[x]:
		if nodes not in visi:
			stack.append(nodes)
			visi.add(nodes)
			depth[nodes] = depth[x] + 1
			if deg[nodes] == 1:
				fn = 1
	if fn:
		cnt += 1
	if x == nod and fn == 1:
		gg = 1
fl = 0
for i in leavs:
	if depth[i] % 2:
		fl = 1
if fl:
	print(3, end=' ')
else:
	print(1, end=' ')
if gg == 0:
	cnt += 1
print(n + cnt - 1 - len(leavs))


import sys
sys.setrecursionlimit(11000)
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__

def go():
	n = int(input())
	if n == 2:
		return '1 1'
	e = {i: set() for i in range(1, n + 1)}
	rank = [0] * (n + 1)
	root = -1
	for _ in range(n - 1):
		(a, b) = map(int, input().split())
		e[a].add(b)
		e[b].add(a)
		rank[a] += 1
		rank[b] += 1
		if rank[a] > 1:
			root = a
		if rank[b] > 1:
			root = b
	mx = n - 1
	for a in range(1, n + 1):
		cnt = sum((rank[b] == 1 for b in e[a]))
		mx -= max(0, cnt - 1)
	(ev, od) = (False, False)
	que = [root]
	i = 0
	dep = [0] * (n + 1)
	done = {root}
	while i < len(que):
		v = que[i]
		if len(e[v]) == 1:
			if dep[v] % 2 == 0:
				ev = True
			if dep[v] % 2 == 1:
				od = True
		for w in e[v]:
			if w not in done:
				que.append(w)
				dep[w] = dep[v] + 1
				done.add(w)
		i += 1
	if ev and od:
		mn = 3
	else:
		mn = 1
	return f'{mn} {mx}'
t = 1
ans = []
for _ in range(t):
	ans.append(str(go()))
print('\n'.join(ans))


import sys
import collections
import threading

def main():
	input = sys.stdin.readline
	n = int(input())
	d = collections.defaultdict(list)
	try:
		for i in range(1, n):
			(a, b) = map(int, input().split())
			d[a].append(b)
			d[b].append(a)
		parents = set()
		cnt = 0
		for key in d:
			if len(d[key]) == 1:
				cnt += 1
				parents.add(*d[key])
				leave = key

		def dfsmin(par, node, h, result):
			for i in d[node]:
				if i != par:
					dfsmin(node, i, h + 1, result)
			if len(d[node]) == 1:
				result[h % 2] += 1
			return result
		minans = 1
		if dfsmin(-1, leave, 0, [0, 0])[1] > 0:
			minans = 3
		maxans = n - 1 - cnt + len(parents)
		print(minans, maxans)
	except RuntimeError as e:
		print(e)
sys.setrecursionlimit(2097152)
threading.stack_size(134217728)
main_thread = threading.Thread(target=main)
main_thread.start()
main_thread.join()


n = int(input())
g = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = [int(s) - 1 for s in input().split()]
	g[a].append(b)
	g[b].append(a)
ls = []
for i in range(n):
	if len(g[i]) == 1:
		ls.append(i)
maxans = n - 1
ls_set = set(ls)
for i in range(n):
	ints = len(ls_set.intersection(g[i]))
	maxans -= max(ints - 1, 0)
minans = 1
vd = set()
st = [(ls[0], 0)]
while len(st) > 0:
	(v, d) = st.pop()
	vd.add(v)
	if len(g[v]) == 1 and d % 2 == 1:
		minans = 3
		break
	for w in g[v]:
		if w not in vd:
			st.append((w, d + 1))
print(minans, maxans)


import random

def getVal(used):
	x = random.randint(1, 10 ** 40)
	while x in used:
		x = random.randint(1, 10 ** 40)
	return x

def solve(edges, n, leaf):
	stack = [leaf]
	dp = [0] * (n + 1)
	dp2 = [0] * (n + 1)
	one = True
	visited = set()
	used = set()
	while stack:
		curr = stack.pop()
		if curr not in visited:
			visited.add(curr)
			if len(edges[curr]) == 1 and dp2[curr] != 0:
				one = False
			for kid in edges[curr]:
				if kid not in visited:
					dp2[kid] = dp2[curr] ^ 1
					stack.append(kid)
					val = getVal(used)
					if len(edges[kid]) == 1:
						used.add(dp[curr])
						dp[kid] = 0
					else:
						dp[kid] = dp[curr] ^ val
						used.add(val)
	if one:
		min_val = 1
	else:
		min_val = 3
	print(min_val, len(used))

def main():
	n = int(input())
	edges = {}
	for i in range(1, n + 1):
		edges[i] = []
	for i in range(n - 1):
		(a, b) = map(int, input().split())
		edges[a].append(b)
		edges[b].append(a)
	for i in edges.keys():
		if len(edges[i]) == 1:
			leaf = i
			break
	solve(edges, n, leaf)
main()


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10 ** 8)
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 51, func=lambda a, b: a & b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

def main():
	n = int(input())
	m = n - 1
	graph = defaultdict(list)
	deg = [0] * n
	ro = 0
	for i in range(m):
		(a, b) = map(int, input().split())
		deg[a - 1] += 1
		deg[b - 1] += 1
		if deg[a - 1] > 1:
			ro = a - 1
		elif deg[b - 1] > 1:
			ro = b - 1
		graph[a - 1].append(b - 1)
		graph[b - 1].append(a - 1)
	visited = [False] * n
	d = set()
	s = set()

	def dfs(v, dist, k):
		if deg[v] == 1 and k not in d:
			d.add(k)
		if deg[v] == 1:
			s.add(dist % 2)
		visited[v] = True
		for i in graph[v]:
			if visited[i] == False:
				dfs(i, dist + 1, v)
	dfs(ro, 0, -1)
	mi = 0
	ma = n - 1
	if len(s) == 1:
		mi = 1
	else:
		mi = 3
	for i in range(n):
		if deg[i] == 1:
			ma -= 1
	ma += len(d)
	print(mi, ma)
t = threading.Thread(target=main)
t.start()
t.join()


n = int(input())
g = [[] for i in range(n)]
L = [-1] * n
for i in range(n - 1):
	(a, b) = map(int, input().split(' '))
	a -= 1
	b -= 1
	g[a] += [b]
	g[b] += [a]
L[0] = 0
q = [0]
i = 0
odd = 0
even = 0
x = 0
while i < len(q):
	a = q[i]
	if len(g[a]) == 1:
		if L[a]:
			odd += 1
		else:
			even += 1
	i += 1
	for b in g[a]:
		if L[b] != -1:
			continue
		L[b] = 1 - L[a]
		q += [b]
for a in range(n):
	s = 0
	for b in g[a]:
		if len(g[b]) == 1:
			s += 1
	if s:
		x += s - 1
print(1 + 2 * (odd * even > 0), n - x - 1)


n = int(input())
l = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	l[a].append(b)
	l[b].append(a)
maxans = n - 1
v = [0] * n
leaf = []
for i in range(len(l)):
	k = l[i]
	if len(k) == 1:
		if v[k[0]] == 1:
			maxans -= 1
		else:
			v[k[0]] = 1
		leaf.append(i)
q = [0]
visited = [-1] * n
visited[0] = 0
while q:
	t = q.pop()
	for i in l[t]:
		if visited[i] == -1:
			q.append(i)
			visited[i] = 1 - visited[t]
k = visited[leaf[0]]
for i in leaf:
	if visited[i] != k:
		minans = 3
		break
else:
	minans = 1
print(minans, maxans)


import sys
input = sys.stdin.buffer.readline
from collections import deque

def prog():
	n = int(input())
	adj_list = [[] for i in range(n + 1)]
	for i in range(n - 1):
		(a, b) = map(int, input().split())
		adj_list[a].append(b)
		adj_list[b].append(a)
	leaves = set()
	for i in range(1, n + 1):
		if len(adj_list[i]) == 1:
			leaves.add(i)
	for i in leaves:
		root = i
		break
	q = deque([root])
	dists = [0 for i in range(n + 1)]
	visited = set()
	while q:
		curr = q.popleft()
		for neighbor in adj_list[curr]:
			if neighbor not in visited:
				dists[neighbor] = dists[curr] + 1
				q.append(neighbor)
				visited.add(neighbor)
	odd = False
	for leave in leaves:
		if dists[leave] % 2 == 1:
			odd = True
			break
	if odd:
		minimum = 3
	else:
		minimum = 1
	distinct_leaves = 0
	for i in range(1, n + 1):
		for neighbor in adj_list[i]:
			if neighbor in leaves:
				distinct_leaves += 1
				break
	print(minimum, n - 1 - len(leaves) + distinct_leaves)
prog()


import os
import sys
input = sys.stdin.buffer.readline
from collections import deque
from queue import PriorityQueue
import math

class CF(object):

	def __init__(self):
		self.n = int(input())
		self.g = [[] for _ in range(self.n)]
		for _ in range(self.n - 1):
			(x, y) = list(map(int, input().split()))
			x -= 1
			y -= 1
			self.g[x].append(y)
			self.g[y].append(x)
		pass
		self.vis = [0] * self.n
		self.f = [-1] * self.n
		self.h = [0] * self.n
		self.leaf = []
		for i in range(self.n):
			if len(self.g[i]) == 1:
				self.leaf.append(i)
		pass
		self.root = self.leaf[0]

	def bfs(self):
		que = deque([self.root])
		self.vis[self.root] = True
		while que:
			now = que.popleft()
			for to in self.g[now]:
				if not self.vis[to]:
					self.h[to] = self.h[now] + 1
					self.vis[to] = True
					self.f[to] = now
					que.append(to)
			pass
		pass

	def check(self):
		for i in range(1, len(self.leaf)):
			if self.h[self.leaf[i]] % 2 != 0:
				return False
		pass
		return True

	def main(self):
		self.bfs()
		ans_min = None
		if self.check():
			ans_min = 1
		else:
			ans_min = 3
		ans_max = self.n - 1
		cnt = 0
		self.vis = [0] * self.n
		for i in range(1, len(self.leaf)):
			if self.h[self.leaf[i]] == 2:
				cnt += 1
			elif self.vis[self.f[self.leaf[i]]]:
				cnt += 1
			pass
			self.vis[self.f[self.leaf[i]]] = True
		pass
		ans_max = ans_max - cnt
		print(str(ans_min) + ' ' + str(ans_max))
cf = CF()
cf.main()
pass


import sys
input = sys.stdin.readline
n = int(input())
neigh = [[] for i in range(n)]
l = []
for i in range(n - 1):
	(a, b) = list(map(int, input().split()))
	a -= 1
	b -= 1
	neigh[a].append(b)
	neigh[b].append(a)
	l.append((a, b))
edges = set()
for (a, b) in l:
	if len(neigh[a]) == 1:
		a = -1
	if len(neigh[b]) == 1:
		b = -1
	if a > b:
		(a, b) = (b, a)
	edges.add((a, b))
MAX = len(edges)
leafDepth = []
visited = [False] * n
from collections import deque
q = deque()
q.append((0, 0))
while q:
	(nex, d) = q.popleft()
	if not visited[nex]:
		visited[nex] = True
		if len(neigh[nex]) == 1:
			leafDepth.append(d)
		for v in neigh[nex]:
			q.append((v, d + 1))
MIN = 1
corr = leafDepth.pop() % 2
for d in leafDepth:
	if d % 2 != corr:
		MIN = 3
print(MIN, MAX)


from collections import defaultdict, deque
import os

def get_neighbors(edges):
	neighbors = defaultdict(set, {})
	for (v1, v2) in edges:
		if v1 != v2:
			neighbors[v1].add(v2)
			neighbors[v2].add(v1)
	return dict(neighbors)

def is_all_even(adj, root):
	seen = set()
	fringe = {root}
	dist = 1
	while fringe:
		new_fringe = set()
		for node in fringe:
			seen.add(node)
			for n in adj[node]:
				if len(adj[n]) == 1 and dist % 2 == 1:
					return False
				elif n not in seen:
					new_fringe.add(n)
		fringe = new_fringe
		dist += 1
	return True

def solve(edges):
	adj = get_neighbors(edges)
	leaves = [i for (i, j) in adj.items() if len(j) == 1]
	m = 1 if is_all_even(adj, leaves[0]) else 3
	parents = set((k for l in leaves for k in adj[l]))
	M = len(adj) - (len(leaves) - len(parents)) - 1
	return (m, M)

def pp(input):
	n = int(input())
	edges = [tuple(map(int, input().split(' '))) for _ in range(n - 1)]
	print(' '.join(map(str, solve(edges))))
if 'paalto' in os.getcwd():
	from string_source import string_source
	pp(string_source('6\n1 3\n2 3\n3 4\n4 5\n5 6'))
	pp(string_source('6\n1 3\n2 3\n3 4\n4 5\n4 6'))
	pp(string_source('7\n1 2\n2 7\n3 4\n4 7\n5 6\n6 7'))
else:
	pp(input)


from collections import deque
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(300000)

def dfs(root):
	stack = [root]
	while len(stack) != 0:
		element = stack.pop()
		for i in tree[element]:
			if num[i] == -1:
				stack.append(i)
				num[i] = 1 - num[element]

def bfs(root):
	queue = [root]
	queue = deque(queue)
	vis = [-1] * n
	while len(queue) != 0:
		element = queue.popleft()
		vis[element] = 1
		for i in tree[element]:
			if vis[i] == -1:
				queue.append(i)
				child[element].append(i)
				vis[i] = 1
			if len(tree[element]) == 1:
				leaf.append(element)
n = int(input())
tree = [[] for i in range(n)]
child = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = list(map(int, input().split()))
	tree[a - 1].append(b - 1)
	tree[b - 1].append(a - 1)
leaf = []
bfs(0)
num = [-1] * n
num[leaf[0]] = 0
dfs(leaf[0])
minimum = 1
for i in leaf:
	if num[i] != num[leaf[0]]:
		minimum = 3
		break
maximum = n - 1
leaf = set(leaf)
for i in range(n):
	flag = 0
	for j in tree[i]:
		if j in leaf:
			maximum -= 1
			flag = 1
	if flag:
		maximum += 1
print(minimum, maximum)


n = int(input())
gs = [[] for _ in range(n)]
for _ in range(n - 1):
	(u, v) = map(int, input().split())
	u -= 1
	v -= 1
	gs[u].append(v)
	gs[v].append(u)
for (root, u) in enumerate(gs):
	if len(u) > 1:
		break
leaves = []
q = [root]
ds = [None] * n
ds[root] = 0
par = [None] * n
while q:
	u = q.pop()
	if len(gs[u]) == 1:
		leaves.append(u)
	for v in gs[u]:
		if ds[v] is not None:
			continue
		q.append(v)
		ds[v] = ds[u] + 1
		par[v] = u
dodd = False
deven = False
pars = [0] * n
for leave in leaves:
	if ds[leave] % 2:
		dodd = True
	else:
		deven = True
	pars[par[leave]] += 1
samepar = 0
for p in pars:
	if not p:
		continue
	samepar += p - 1
ansmin = 3 if dodd and deven else 1
ansmax = n - 1 - samepar
print(ansmin, ansmax)


import sys
from array import array
import typing as Tp

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def main():
	n = int(input())
	adj = [[] for _ in range(n)]
	deg = [0] * n
	for (u, v) in (map(int, input().split()) for _ in range(n - 1)):
		adj[u - 1].append(v - 1)
		adj[v - 1].append(u - 1)
		deg[u - 1] += 1
		deg[v - 1] += 1
	start = [i for i in range(n) if deg[i] == 1][0]
	stack = [(start, -1, 0)]
	(ans_min, ans_max) = (1, -1)
	while stack:
		(v, par, dist) = stack.pop()
		ans_max += 1
		dist += 1
		has_leaf = 0
		for dest in adj[v]:
			if dest == par:
				continue
			if deg[dest] == 1:
				has_leaf = 1
				if dist & 1:
					ans_min = 3
				continue
			stack.append((dest, v, dist))
		if dist != 2:
			ans_max += has_leaf
	print(ans_min, ans_max)
main()


from collections import deque
from collections import defaultdict
N = int(input())
G = [[] for i in range(N + 1)]
for i in range(N - 1):
	(a, b) = map(int, input().split())
	G[a].append(b)
	G[b].append(a)
maxi = N - 1
S = -1
Leaves = []
D = defaultdict(int)
for i in range(1, N + 1):
	if len(G[i]) == 1:
		S = i
		D[G[i][0]] += 1
		Leaves.append(i)
for value in D.values():
	maxi -= value - 1
q = deque()
visited = [False for i in range(N + 1)]
dis = [0 for i in range(N + 1)]
visited[S] = True
q.append(S)
while q:
	x = q.popleft()
	for node in G[x]:
		if visited[node] == False:
			dis[node] = dis[x] + 1
			visited[node] = True
			q.append(node)
if all((dis[S] % 2 == dis[node] % 2 for node in Leaves)):
	mini = 1
else:
	mini = 3
print(mini, maxi)


import sys
from collections import deque
input = sys.stdin.readline
n = int(input())
info = [list(map(int, input().split())) for i in range(n - 1)]
tree = [[] for i in range(n)]
for (a, b) in info:
	a -= 1
	b -= 1
	tree[a].append(b)
	tree[b].append(a)
max_ = n - 1
for v in range(n):
	cnt = 0
	for nxt_v in tree[v]:
		if len(tree[nxt_v]) == 1:
			cnt += 1
	max_ -= max(cnt - 1, 0)
visited = [-1] * n
q = deque([0])
visited[0] = 0
while q:
	v = q.popleft()
	for nxt_v in tree[v]:
		if visited[nxt_v] != -1:
			continue
		visited[nxt_v] = visited[v] + 1
		q.append(nxt_v)
min_ = 3
for i in range(n):
	if len(tree[i]) == 1:
		if visited[i] % 2 == 0:
			break
else:
	min_ = 1
for i in range(n):
	if len(tree[i]) == 1:
		if (visited[i] + 1) % 2 == 0:
			break
else:
	min_ = 1
print(min_, max_)