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]

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Bit manipulation

Graph traversal

Constructive algorithms

Greedy algorithms

Tree algorithms

Mathematics


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


n = int(input())
E = [[int(x) - 1 for x in input().split()] for i in range(n - 1)]
G = [[] for i in range(n)]
for (u, v) in E:
	G[u].append(v)
	G[v].append(u)
root = next((i for i in range(n) if len(G[i]) > 1))
pa = [None] * n
d = [None] * n
useless = [0] * n
q = [(root, 0, root)]
while q:
	(parent, depth, i) = q.pop()
	pa[i] = parent
	d[i] = depth
	G[i].sort(key=lambda j: len(G[j]))
	for j in G[i]:
		if pa[j] == None:
			q.append((i, depth + 1, j))
		if len(G[j]) == 1 and j != G[i][0]:
			useless[j] = 1
leaves = [i for i in range(n) if len(G[i]) == 1]
ans_min = 1 if len(set((d[i] % 2 for i in leaves))) == 1 else 3
ans_max = n - 1 - sum(useless)
print(ans_min, ans_max)


import sys
input = sys.stdin.readline

def DFS(i):
	visited = {i: True}
	stack = [(i, 0)]
	while len(stack) != 0:
		(tail, depth) = stack.pop(-1)
		flag = True
		for each in neigh[tail]:
			if each not in visited:
				visited[each] = True
				flag = False
				stack.append((each, depth + 1))
		if flag:
			leafDepth.append(depth)
n = int(input())
neigh = [[] for i in range(n)]
l = []
for i in range(n - 1):
	(a, b) = 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 = []
DFS(0)
if len(neigh[0]) == 1:
	MIN = 1 if all([True if i % 2 == 0 else False for i in leafDepth]) else 3
else:
	MIN = 1 if all([True if i % 2 == 0 else False for i in leafDepth]) or all([True if i % 2 == 1 else False for i in leafDepth]) else 3
print(MIN, MAX)


n = int(input())
tree = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	tree[a - 1].append(b - 1)
	tree[b - 1].append(a - 1)
d = dict()
for i in range(n):
	if len(tree[i]) == 1:
		x = tree[i][0]
		if x in d:
			d[x] += 1
		else:
			d[x] = 1
		st = i
ma = n - 1
for i in d:
	ma -= d[i] - 1
inf = 10000000000000000
dep = [inf for i in range(n)]
dep[st] = 0
from collections import deque
d = deque()
d.append(st)
dep_sub = 0
while len(d):
	dep_sub += 1
	l = len(d)
	for _ in range(l):
		p = d.popleft()
		for i in tree[p]:
			if dep[i] == inf:
				dep[i] = dep_sub
				d.append(i)
if any((dep[i] % 2 and len(tree[i]) == 1 for i in range(n))):
	mi = 3
else:
	mi = 1
print(mi, ma)


size = int(input())
graph = [[] for i in range(size)]
for _ in range(1, size):
	(a, b) = (int(x) for x in input().split())
	a -= 1
	b -= 1
	graph[a] += [b]
	graph[b] += [a]
leafs = [node for node in range(0, len(graph)) if len(graph[node]) == 1]
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)):
	minF = 1
else:
	minF = 3
group = [0] * len(graph)
for leaf in leafs:
	parent = graph[leaf][0]
	group[parent] += 1
maxF = len(graph) - 1
for size in group:
	if size >= 2:
		maxF -= size - 1
print(str(minF) + ' ' + str(maxF))


n = int(input())
ls = [[] for x in range(n)]
for inp in range(n - 1):
	(point1, point2) = [int(x) - 1 for x in input().split()]
	ls[point1].append(point2)
	ls[point2].append(point1)
bottom = []
e = [0] * n
max_res = n - 1
for i in range(n):
	temp = ls[i]
	if len(temp) == 1:
		if e[temp[0]] == 1:
			max_res -= 1
		else:
			e[temp[0]] = 1
		bottom.append(i)
queue = [0]
seen = [-1] * n
seen[0] = 0
while queue:
	point = queue.pop()
	for i in ls[point]:
		if seen[i] == -1:
			queue.append(i)
			seen[i] = 1 - seen[point]
f = seen[bottom[0]]
for i in bottom:
	if seen[i] != f:
		min_res = 3
		break
else:
	min_res = 1
print(min_res, max_res)


n = int(input())
l = [[] for _ in range(n)]
for _ in range(n - 1):
	(p1, p2) = map(lambda x: x - 1, map(int, input().split()))
	l[p1].append(p2)
	l[p2].append(p1)
leaf = []
e = [0] * n
maxans = n - 1
for i in range(n):
	temp = l[i]
	if len(temp) == 1:
		if e[temp[0]] == 1:
			maxans -= 1
		else:
			e[temp[0]] = 1
		leaf.append(i)
q = [0]
visited = [-1] * n
visited[0] = 0
while q:
	node = q.pop()
	for i in l[node]:
		if visited[i] == -1:
			q.append(i)
			visited[i] = 1 - visited[node]
f = visited[leaf[0]]
for i in leaf:
	if visited[i] != f:
		minans = 3
		break
else:
	minans = 1
print(minans, maxans)


from sys import stdin
input = stdin.readline

class N:

	def __init__(self, v) -> None:
		self.v = v
		self.c = set()
		self.l = False
n = int(input())
arr = [N(i) for i in range(n)]
es = set()
for _ in range(n - 1):
	(x, y) = map(int, input().split())
	x -= 1
	y -= 1
	(x, y) = (min(x, y), max(x, y))
	es.add((x, y))
	arr[x].c.add(arr[y])
	arr[y].c.add(arr[x])
ps = set()
for x in arr:
	if len(x.c) == 1:
		x.l = True
		ps.add(list(x.c)[0])
for p in ps:
	kept = False
	rs = []
	for c in p.c:
		if c.l:
			if kept:
				x = p.v
				y = c.v
				(x, y) = (min(x, y), max(x, y))
				es.discard((x, y))
				rs.append(c)
			else:
				kept = True
	for c in rs:
		p.c.discard(c)
root = ps.pop()
stk = [(root, 0)]
viz = set()
ls = []
while stk:
	(root, l) = stk.pop()
	viz.add(root)
	for c in root.c:
		if c not in viz:
			if c.l:
				ls.append(l + 1)
			else:
				stk.append((c, l + 1))
if len(es) > 1:
	print(1 + 2 * int(len(set([l % 2 for l in ls])) == 2), len(es))
else:
	print(1, 1)


I = lambda : list(map(int, input().split()))
(n,) = I()
g = [[] for i in range(n + 1)]
for i in range(n - 1):
	(x, y) = I()
	g[x].append(y)
	g[y].append(x)
leaf = []
for i in range(1, n + 1):
	if len(g[i]) == 1:
		leaf.append(i)
st = [1]
visi = [-1] * (n + 1)
visi[1] = 0
while st:
	x = st.pop()
	for y in g[x]:
		if visi[y] == -1:
			visi[y] = 1 - visi[x]
			st.append(y)
ch = visi[leaf[0]]
fl = 1
temp = 0
for i in leaf:
	if visi[i] != ch:
		fl = 0
mi = 1
if not fl:
	mi = 3
an = [0] * (n + 1)
ma = n - 1
for i in leaf:
	for j in g[i]:
		if an[j] == 1:
			ma -= 1
		else:
			an[j] = 1
print(mi, ma)


from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def main():
	n = int(input())
	adj = [[] for _ in range(n + 1)]
	for _ in range(n - 1):
		(a, b) = readIntArr()
		adj[a].append(b)
		adj[b].append(a)
	for node in range(1, n + 1):
		if len(adj[node]) > 1:
			root = node
			break

	@bootstrap
	def dfs(node, parent):
		ret = [False, False]
		if len(adj[node]) == 1:
			ret[1] = True
		else:
			for node2 in adj[node]:
				if node2 != parent:
					(childHasOdd, childHasEven) = (yield dfs(node2, node))
					ret[0] = childHasEven or ret[0]
					ret[1] = childHasOdd or ret[1]
		yield ret
	(hasOdd, hasEven) = dfs(root, -1)
	if hasOdd and hasEven:
		minAns = 3
	else:
		minAns = 1
	allLeaves = []
	for node in range(1, n + 1):
		if len(adj[node]) == 1:
			allLeaves.append(node)
	nodeLeafConnections = [0 for _ in range(n + 1)]
	for leaf in allLeaves:
		nodeLeafConnections[adj[leaf][0]] += 1
	maxAns = n - 1
	for cnt in nodeLeafConnections:
		maxAns -= max(0, cnt - 1)
	print('{} {}'.format(minAns, maxAns))
	return
import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

def readIntArr():
	return [int(x) for x in input().split()]
inf = float('inf')
MOD = 10 ** 9 + 7
main()


import sys, os
input = sys.stdin.buffer.readline
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)
for i in range(1, n + 1):
	if len(g[i]) == 1:
		root = i
		break
(dep, stk) = ([0] * (n + 1), [(root, 0)])
while len(stk):
	(nod, t) = stk[-1]
	dep[nod] = 1 + dep[t]
	stk.pop()
	for nn in g[nod]:
		if nn != t:
			stk.append((nn, nod))
frunze = []
for i in range(1, n + 1):
	if len(g[i]) == 1:
		frunze.append(dep[i])
frunze.sort()
i = 0
while i < len(frunze) and (i == 0 or ~(frunze[i] - frunze[i - 1]) & 1):
	i += 1
if i >= len(frunze):
	print(1, end=' ')
else:
	print(3, end=' ')
m = n - 1 - len(frunze) + 1
for i in range(1, n + 1):
	if dep[i] > 2 and len(g[i]) > 1:
		add = 0
		for nn in g[i]:
			add |= len(g[nn]) == 1
		m += add
print(m)


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

def main():
	n = int(input())
	path = defaultdict(set)
	parent = [0] * (n + 1)
	for _ in range(n - 1):
		(a, b) = map(int, input().split())
		path[a].add(b)
		path[b].add(a)
	root = -1
	z = [0] * (n + 1)
	for i in path:
		if len(path[i]) > 1:
			root = i
		else:
			x = path[i].pop()
			parent[x] += 1
			path[i].add(x)
			z[i] = 1
	st = [root]
	ans = 1
	while len(st):
		if not len(path[st[-1]]):
			x = st.pop()
			if len(st):
				z[st[-1]] |= 3 ^ z[x]
				if z[st[-1]] == 3:
					ans = 3
					break
			continue
		i = path[st[-1]].pop()
		path[i].remove(st[-1])
		st.append(i)
	ans1 = n - 1
	for i in parent:
		ans1 -= max(0, i - 1)
	print(ans, ans1)
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()


import sys, io, os
BUFSIZE = 8192

class FastIO(io.IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = io.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(io.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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
N = int(input())
E = [[] for _ in range(N + 1)]
for _ in range(N - 1):
	(v, u) = map(int, input().split())
	E[v].append(u)
	E[u].append(v)
ans2 = N - 1
for v in range(1, N + 1):
	n = 0
	for u in E[v]:
		n += len(E[u]) == 1
	ans2 -= max(0, n - 1)
for start in range(1, N + 1):
	if len(E[start]) == 1:
		break
q = [start]
pa = False
Closed = [False] * (N + 1)
Closed[start] = True
ans1 = 1
while q:
	q_new = []
	for v in q:
		Closed[v] = True
		v_is_leaf = True
		for u in E[v]:
			if Closed[u]:
				continue
			v_is_leaf = False
			q_new.append(u)
		if pa and v_is_leaf:
			ans1 = 3
	q = q_new
	pa = not pa
print(ans1, ans2)


from sys import stdin, stdout

def main():
	n = int(stdin.readline())
	g = [[] for _ in range(n + 1)]
	k = [[] for _ in range(n + 1)]
	already = [0] * (n + 1)
	already1 = [0] * (n + 1)
	even = [False] * (n + 1)
	odd = [False] * (n + 1)
	for _ in range(n - 1):
		(a, b) = list(map(int, stdin.readline().split()))
		g[a].append(b)
		g[b].append(a)
		k[a].append(b)
		k[b].append(a)
	start = -1
	for i in range(1, n + 1):
		if len(g[i]) > 1:
			start = i
			break
	stack = [start]
	mn = 1
	mx = n - 1
	while stack:
		x = stack[-1]
		if already[x] == 0:
			already[x] = -1
		still_deep = False
		if len(g[x]) > 0:
			y = g[x][-1]
			if already[y] == 0:
				stack.append(y)
				g[x].pop()
				still_deep = True
				continue
			else:
				g[x].pop()
				continue
		if still_deep is True:
			continue
		stack.pop()
		if already[x] == -1 and len(k[x]) == 1:
			already[x] = 1
			already1[stack[-1]] += 1
			odd[stack[-1]] = True
			continue
		if odd[x] == even[x]:
			mn = 3
		if already1[x] > 0:
			mx -= already1[x] - 1
		already[x] = 1
		if stack:
			y = stack[-1]
			if odd[x] is True:
				even[y] = True
			if even[x] is True:
				odd[y] = True
	stdout.write(str(mn) + ' ' + str(mx))
main()


import sys
n = int(sys.stdin.readline().strip())
N = [[] for i in range(0, n)]
C = [-1 for i in range(0, n)]
for i in range(0, n - 1):
	(a, b) = list(map(int, sys.stdin.readline().strip().split()))
	(a, b) = (a - 1, b - 1)
	N[a].append(b)
	N[b].append(a)
C[0] = 0
L0 = [0]
L1 = []
while len(L0) + len(L1) > 0:
	for i in L0:
		for j in N[i]:
			if C[j] == -1:
				C[j] = 1
				L1.append(j)
	L0 = []
	for i in L1:
		for j in N[i]:
			if C[j] == -1:
				C[j] = 0
				L0.append(j)
	L1 = []
f = 1
F = n - 1
L = []
M = []
for i in range(0, n):
	if len(N[i]) == 1:
		L.append(N[i])
		M.append(i)
L.sort()
for i in range(0, len(L) - 1):
	if L[i] == L[i + 1]:
		F = F - 1
	if C[M[i]] != C[M[i + 1]]:
		f = 3
print(f, F)


from collections import defaultdict
from queue import deque
from sys import stdin, stdout

def arrinp():
	return [*map(int, stdin.readline().split(' '))]

def mulinp():
	return map(int, stdin.readline().split(' '))

def intinp():
	return int(stdin.readline())

def solution():
	n = intinp()
	adj_list = [[] for i in range(n + 1)]
	for i in range(n - 1):
		(a, b) = mulinp()
		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)
testcases = 1
for _ in range(testcases):
	solution()


import sys
readline = sys.stdin.readline

def parorder(Edge, p):
	N = len(Edge)
	par = [0] * N
	par[p] = -1
	stack = [p]
	order = []
	visited = set([p])
	ast = stack.append
	apo = order.append
	while stack:
		vn = stack.pop()
		apo(vn)
		for vf in Edge[vn]:
			if vf in visited:
				continue
			visited.add(vf)
			par[vf] = vn
			ast(vf)
	return (par, order)

def getcld(p):
	res = [[] for _ in range(len(p))]
	for (i, v) in enumerate(p[1:], 1):
		res[v].append(i)
	return res
N = int(readline())
Edge = [[] for _ in range(N)]
for _ in range(N - 1):
	(a, b) = map(int, readline().split())
	a -= 1
	b -= 1
	Edge[a].append(b)
	Edge[b].append(a)
Leaf = [i for i in range(N) if len(Edge[i]) == 1]
sLeaf = set(Leaf)
for i in range(N):
	if i not in sLeaf:
		root = i
		break
(P, L) = parorder(Edge, root)
dp = [0] * N
used = set([root])
stack = [root]
while stack:
	vn = stack.pop()
	for vf in Edge[vn]:
		if vf not in used:
			used.add(vf)
			stack.append(vf)
			dp[vf] = 1 - dp[vn]
if len(set([dp[i] for i in Leaf])) == 1:
	mini = 1
else:
	mini = 3
k = set()
for l in Leaf:
	k.add(P[l])
maxi = N - 1 - len(Leaf) + len(k)
print(mini, maxi)


import sys
sys.setrecursionlimit(10 ** 6)
n = int(input().strip())
conns = [set() for i in range(n + 1)]
for i in range(n - 1):
	(a, b) = [int(d) for d in input().strip().split()]
	conns[a].add(b)
	conns[b].add(a)
even = False
odd = False
for i in range(1, n + 1):
	if len(conns[i]) > 1:
		first = i
		break
q = [(first, -1, 0)]
index = 0
while index < len(q):
	(node, parent, dist) = q[index]
	index += 1
	if len(conns[node]) == 1:
		if dist % 2 == 0:
			even = True
		else:
			odd = True
	for c in conns[node]:
		if c != parent:
			q += [(c, node, dist + 1)]
num_leaves = [0 for i in range(n + 1)]
for i in range(1, n + 1):
	if len(conns[i]) == 1:
		for c in conns[i]:
			num_leaves[c] += 1
ma = n - 1
for val in num_leaves:
	if val > 0:
		ma -= val - 1
if even and odd:
	mi = 3
else:
	mi = 1
print(mi, ma)


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
n = int(input())
d = defaultdict(list)
leaves = defaultdict(int)
for i in range(n - 1):
	(a, b) = list(map(int, input().split()))
	d[a].append(b)
	d[b].append(a)
	leaves[a] += 1
	leaves[b] += 1
leaf = {}
non_leaves = {}
for (l, i) in leaves.items():
	if i == 1:
		leaf[l] = 1
		u = d[l][0]
		non_leaves[u] = 1
mx = n - 1 - (len(leaf) - len(non_leaves))
mn = 1
root = list(leaf.keys())[0]
queue = [(root, 0)]
visited = [False] * (n + 1)
while queue:
	(p, dist) = queue.pop(0)
	if leaf.get(p, 0):
		if dist % 2 != 0:
			mn = 3
			break
	visited[p] = True
	for i in d[p]:
		if visited[i] == False:
			visited[i] = True
			queue.append((i, dist + 1))
print(mn, mx)


import sys
(n, *ab) = map(int, sys.stdin.read().split())
graph = [[] for _ in range(n)]
for (a, b) in zip(*[iter(ab)] * 2):
	a -= 1
	b -= 1
	graph[a].append(b)
	graph[b].append(a)

def main():
	rank = [None] * n
	rank[0] = 0
	parent = [None] * n
	leaves = []
	stack = [0]
	while stack:
		u = stack.pop()
		if not u == 0 and len(graph[u]) == 1:
			leaves.append(u)
			continue
		for v in graph[u]:
			if v == parent[u]:
				continue
			parent[v] = u
			rank[v] = rank[u] + 1
			stack.append(v)
	if len(graph[0]) == 1:
		leaves.append(0)
		parent[0] = graph[0][0]
		parent[graph[0][0]] = None
	pars = set()
	for leaf in leaves:
		pars.add(parent[leaf])
	ma = n - 1 - (len(leaves) - len(pars))
	rs = set([rank[leaf] & 1 for leaf in leaves])
	mi = 1 if len(rs) == 1 else 3
	print(mi, ma)
main()


n = int(input())
dic = {}
dicle = {}
for i in range(n):
	dic[i + 1] = []
	dicle[i + 1] = 0
for i in range(n - 1):
	(x, y) = map(int, input().split())
	dic[x].append(y)
	dic[y].append(x)
	dicle[x] += 1
	dicle[y] += 1
root = 0
leafcount = 0
se = set({})
for i in dicle:
	if dicle[i] == 1:
		leafcount += 1
		root = i
		se.add(dic[i][0])
maxans = n - 1 - leafcount + len(se)
flag = True
se = {root}
tem = {root}
dis = [0] * (n + 1)
level = 0
while tem:
	level += 1
	tem1 = set({})
	for i in tem:
		xx = dic[i]
		for j in xx:
			if not j in se:
				if level % 2 != 0 and dicle[j] == 1:
					flag = False
				se.add(j)
				tem1.add(j)
				dis[j] = level
	tem = tem1.copy()
if flag:
	print(1, maxans)
else:
	print(3, maxans)


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)


import sys
import math
from collections import deque

def solve():
	f = sys.stdin
	n = int(f.readline())
	edges = [[] for i in range(n)]
	for i in range(n - 1):
		s = f.readline().strip()
		(a, b) = [int(x) for x in s.split(' ', 2)]
		edges[a - 1].append(b - 1)
		edges[b - 1].append(a - 1)
	root = 0
	for i in range(n):
		if len(edges[i]) > 1:
			root = i
			break
	odd_dist = False
	even_dist = False
	minf = 1
	maxf = n - 1
	dist = [0 for i in range(n)]
	q = deque()
	q.append(root)
	while len(q) > 0:
		cur = q.popleft()
		child_leaves = 0
		for next in edges[cur]:
			if dist[next] == 0 and next != root:
				q.append(next)
				dist[next] = dist[cur] + 1
			if len(edges[next]) == 1:
				child_leaves += 1
				if dist[next] % 2 == 1:
					odd_dist = True
				else:
					even_dist = True
		if child_leaves > 1:
			maxf = maxf - child_leaves + 1
	if odd_dist and even_dist:
		minf = 3
	print(str(minf) + ' ' + str(maxf))
solve()


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
connectionList = []
for _ in range(n):
	connectionList.append([])
for _ in range(n - 1):
	(p, q) = map(int, input().split())
	connectionList[p - 1].append(q - 1)
	connectionList[q - 1].append(p - 1)
leavesList = []
for i in range(n):
	if len(connectionList[i]) == 1:
		leavesList.append(i)
distance = [-1] * n
distance[0] = 0
dfsStack = [(0, 0)]
while dfsStack:
	(elem, distanceCur) = dfsStack.pop()
	for v in connectionList[elem]:
		if distance[v] == -1:
			dfsStack.append((v, distanceCur + 1))
			distance[v] = distanceCur + 1
mainDist = distance[leavesList[0]]
minAns = 1
for elem in leavesList:
	if (distance[elem] - mainDist) % 2 != 0:
		minAns = 3
		break
oneUpLeaveList = []
for elem in leavesList:
	oneUpLeaveList.append(connectionList[elem][0])
oneUpLeaveList.sort()
uniqueElement = 0
for i in range(len(oneUpLeaveList)):
	if i == 0 or oneUpLeaveList[i - 1] != oneUpLeaveList[i]:
		uniqueElement += 1
maxAns = n - 1 - (len(oneUpLeaveList) - uniqueElement)
print(str(minAns) + ' ' + str(maxAns))


import sys
lines = sys.stdin.readlines()
n = int(lines[0].strip())
edges = {}
for i in range(1, n):
	(u, v) = map(int, lines[i].strip().split(' '))
	if u not in edges:
		edges[u] = []
	if v not in edges:
		edges[v] = []
	edges[u].append(v)
	edges[v].append(u)
leaves = []
parLeave = {}
for u in edges.keys():
	if len(edges[u]) == 1:
		leaves.append(u)
		parLeave[u] = edges[u][0]
maxF = n - (len(leaves) - len(set(parLeave.values()))) - 1
parity = {leaves[0]: 0}
stack = [leaves[0]]
seen = set(stack)
while stack:
	node = stack.pop()
	for adj in edges[node]:
		if adj not in seen:
			parity[adj] = 1 - parity[node]
			stack.append(adj)
			seen.add(adj)
parityOfLeaves = list(map(lambda x: parity[x], leaves))
if min(parityOfLeaves) == max(parityOfLeaves):
	minF = 1
else:
	minF = 3
print('{} {}'.format(minF, maxF))


from collections import defaultdict, deque
from sys import *
input = stdin.readline
n = int(input())
graph = defaultdict(list)
deg = [0] * n
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	graph[a - 1].append(b - 1)
	graph[b - 1].append(a - 1)
	deg[a - 1] += 1
	deg[b - 1] += 1
childLeaves = defaultdict(int)
idx = 0
for i in range(n):
	if deg[i] == 1:
		idx = i
		childLeaves[graph[i][0]] += 1
mAx = n - 1 + len(childLeaves) - sum(childLeaves.values())
dis = defaultdict(int)
dis[idx] = 0
stack = deque()
stack.append(idx)
visited = [0] * n
visited[idx] = 1
mIn = 1
while stack:
	node = stack.pop()
	if not visited[node]:
		visited[node] = 1
	for i in graph[node]:
		if not visited[i]:
			dis[i] = dis[node] + 1
			stack.append(i)
			if deg[i] == 1 and dis[i] % 2:
				mIn = 3
print(mIn, mAx)


mod = 1000000007
eps = 10 ** (-9)

def main():
	import sys
	input = sys.stdin.buffer.readline
	N = int(input())
	adj = [[] for _ in range(N + 1)]
	for _ in range(N - 1):
		(a, b) = map(int, input().split())
		adj[a].append(b)
		adj[b].append(a)
	from collections import deque
	que = deque()
	que.append(1)
	seen = [-1] * (N + 1)
	seen[1] = 0
	par = [0] * (N + 1)
	child = [[] for _ in range(N + 1)]
	seq = []
	while que:
		v = que.popleft()
		seq.append(v)
		for u in adj[v]:
			if seen[u] == -1:
				seen[u] = seen[v] + 1
				par[u] = v
				child[v].append(u)
				que.append(u)
	seq.reverse()
	ok = 1
	flg = -1
	is_leaf = [0] * (N + 1)
	for v in range(1, N + 1):
		if len(adj[v]) == 1:
			if flg == -1:
				flg = seen[v] & 1
			elif flg != seen[v] & 1:
				ok = 0
			is_leaf[v] = 1
	if ok:
		m = 1
	else:
		m = 3
	M = N - 1
	for v in range(1, N + 1):
		cnt = 0
		for u in adj[v]:
			if is_leaf[u]:
				cnt += 1
		if cnt:
			M -= cnt - 1
	print(m, M)
main()


import sys
input = sys.stdin.readline
n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n - 1):
	(u, v) = map(int, input().split())
	u -= 1
	v -= 1
	edge[u].append(v)
	edge[v].append(u)
is_leaf = [False] * n
for i in range(n):
	if len(edge[i]) == 1:
		is_leaf[i] = True
	else:
		start = i
oe = [0, 0]

def dfs(d, p, v):
	queue = [(d, p, v)]
	while queue:
		(d, p, v) = queue.pop()
		if is_leaf[v]:
			oe[d % 2] += 1
			continue
		for nv in edge[v]:
			if nv == p:
				continue
			queue.append((d + 1, v, nv))
dfs(0, -1, start)
if 0 in oe:
	minima = 1
else:
	minima = 3
dim = 0
for i in range(n):
	cnt = 0
	for v in edge[i]:
		cnt += is_leaf[v]
	if cnt > 1:
		dim += cnt - 1
print(minima, n - 1 - dim)


n = int(input())
g = [[] for i in range(n)]
for i in range(n - 1):
	(u, v) = [int(i) - 1 for i in input().split()]
	g[u].append(v)
	g[v].append(u)
leaf = [len(i) == 1 for i in g]
root = -1
mx = n - 1
for i in range(n):
	if leaf[i]:
		root = i
	leafs = 0
	for j in g[i]:
		if leaf[j]:
			leafs += 1
	if leafs > 1:
		mx -= leafs - 1
stack = [(root, -1, 0)]
even = True
while len(stack) > 0:
	(i, j, d) = stack.pop()
	if leaf[i] and d % 2 == 1:
		even = False
		break
	for k in g[i]:
		if k != j:
			stack.append((k, i, d + 1))
mn = 1 if even else 3
print(mn, mx)


from collections import Counter, defaultdict, deque
from math import factorial as fact
import math

def BFS(cmap, v):
	visited = [False] * len(cmap)
	q = deque([v])
	level = 0
	groups = 0
	blue = 0
	red = 0
	while len(q) != 0:
		for i in range(len(q)):
			vertex = q.popleft()
			if not visited[vertex]:
				pos = False
				for nei in cmap[vertex]:
					if len(cmap[nei]) == 1:
						if pos:
							groups += 1
						pos = True
						if level % 2 == 0:
							blue += 1
						else:
							red += 1
				visited[vertex] = True
				q.extend(cmap[vertex])
		level += 1
	return (groups, blue, red)
n = int(input())
connections = [[] for x in range(n)]
for i in range(n - 1):
	(a, b) = [int(x) - 1 for x in input().split()]
	connections[a].append(b)
	connections[b].append(a)
(g, b, r) = BFS(connections, 0)
if b == 0 or r == 0:
	print(1, end=' ')
else:
	print(3, end=' ')
print(n - 1 - g)


import collections, sys
n = int(sys.stdin.readline())
g = []
sys.setrecursionlimit(2 ** 20)
for i in range(n + 1):
	g.append([])
for i in range(n - 1):
	(a, b) = list(map(int, sys.stdin.readline().split(' ')))
	g[a].append(b)
	g[b].append(a)
leaf = {}
mx = n - 1
for i in range(1, n + 1, 1):
	if len(g[i]) == 1:
		leaf[i] = True
	else:
		s = i
for i in range(1, n + 1, 1):
	l = 0
	for v in g[i]:
		if v in leaf:
			l += 1
	if l != 0:
		mx = mx - l + 1
mn = 1
l = s
dst = [0] * (n + 1)
a = collections.deque([])
exp = {}
exp[l] = True
a.append(l)
o = 0
e = 0
while a:
	v = a.pop()
	h = dst[v] + 1
	for u in g[v]:
		if u not in exp:
			dst[u] = h
			exp[u] = True
			a.append(u)
			if u in leaf:
				if h % 2 == 1:
					o += 1
				else:
					e += 1
if o == 0 or e == 0:
	mn = 1
else:
	mn = 3
print(mn, mx)


import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def MI1():
	return map(int1, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]

def main():

	def findmin():
		p = dep[leaf[0]] & 1
		for u in leaf[1:]:
			if dep[u] & 1 != p:
				return 3
		return 1
	n = II()
	to = [[] for _ in range(n)]
	for _ in range(n - 1):
		(u, v) = MI1()
		to[u].append(v)
		to[v].append(u)
	dep = [-1] * n
	dep[0] = 0
	pp = [-1] * n
	stack = [0]
	while stack:
		u = stack.pop()
		for v in to[u]:
			if v == pp[u]:
				continue
			pp[v] = u
			dep[v] = dep[u] + 1
			stack.append(v)
	leaf = []
	for u in range(n):
		if len(to[u]) == 1:
			leaf.append(u)
	mn = findmin()
	st = set()
	cnt = 0
	for u in leaf:
		p = to[u][0]
		if p in st:
			cnt += 1
		else:
			st.add(p)
	mx = n - 1 - cnt
	print(mn, mx)
main()


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)


import os
import sys
from io import BytesIO, IOBase
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')
from collections import deque, defaultdict
n = int(input())
tree = [[] for s in range(n)]
for s in range(n - 1):
	(u, v) = map(int, input().split())
	u -= 1
	v -= 1
	tree[u].append(v)
	tree[v].append(u)
root = 0
for s in range(n):
	if len(tree[s]) > 1:
		root = s
		break
queue = deque([root])
vis = set([root])
depth = 0
cv = 1
depths = defaultdict(list)
dd = {}
depths[depth].append(root)
dd[root] = depth
while len(queue) > 0:
	v0 = queue.popleft()
	for s in tree[v0]:
		if not s in vis:
			queue.append(s)
			vis.add(s)
	cv -= 1
	depths[depth].append(v0)
	dd[v0] = depth
	if cv == 0:
		depth += 1
		cv = len(queue)
odd = 0
even = 0
leaf = set([])
dist = []
for s in range(n):
	if len(tree[s]) == 1:
		leaf.add(s)
		dist.append(dd[s])
		odd += dd[s] % 2
		even += (dd[s] % 2 + 1) % 2
totodd = odd * even
toteven = odd * (odd - 1) // 2 + even * (even - 1) // 2
minnum = 1 + min(1, totodd) * 2
depth -= 1
dict1 = defaultdict(int)
ans = 0
while depth > 0:
	for s in depths[depth]:
		if s in leaf:
			for i in tree[s]:
				if dd[i] < depth:
					ans += 1
					dict1[i] += 1
					if dict1[i] > 1:
						ans -= 1
		else:
			for i in tree[s]:
				if dd[i] < depth:
					ans += 1
	depth -= 1
print(minnum, ans)


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_)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		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 = self.os.read(self._fd, max(self.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 = self.os.read(self._fd, max(self.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:
			self.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')
from collections import defaultdict as dd, deque as dq, Counter as dc
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 998244353

def solve():
	N = getInt()
	graph = dd(set)
	for n in range(N - 1):
		(A, B) = getInts()
		graph[A].add(B)
		graph[B].add(A)
	visited = set()
	global flag
	flag = True

	def bfs(leaf):
		global flag
		queue = dq([(leaf, 0)])
		visited.add(leaf)
		while queue:
			(node, level) = queue.popleft()
			if len(graph[node]) == 1 and level % 2 == 1:
				flag = False
			for neighbour in graph[node]:
				if neighbour not in visited:
					visited.add(neighbour)
					queue.append((neighbour, level + 1))
		return
	for node in graph:
		if len(graph[node]) == 1:
			bfs(node)
			break
	m = 1 if flag else 3
	neighs = set()
	L = 0
	for node in graph:
		if len(graph[node]) == 1:
			neighs.add(next(iter(graph[node])))
			L += 1
	M = N - 1 + len(neighs) - L
	print(m, M)
	return
solve()


from collections import defaultdict
from collections import deque
N = int(input())
edges = [[] for i in range(N)]
for i in range(N - 1):
	(u, v) = [int(_) for _ in input().split()]
	edges[u - 1].append(v - 1)
	edges[v - 1].append(u - 1)
leafs = set()
leaf_count_that_touch_node = defaultdict(int)
for (node_id, neighbours) in enumerate(edges):
	if len(neighbours) == 1:
		leafs.add(node_id)
		leaf_count_that_touch_node[neighbours[0]] += 1
mmax = N - 1
for (n, leaf_count) in leaf_count_that_touch_node.items():
	mmax -= leaf_count - 1
Q = deque()
root = next(iter(leafs))
Q.append(root)
D = {root: 0}
visited = [False] * N
visited[root] = True
while Q:
	node = Q.pop()
	for neighbour in edges[node]:
		if visited[neighbour]:
			continue
		visited[neighbour] = True
		Q.append(neighbour)
		D[neighbour] = D[node] + 1
for leaf in leafs:
	if D[leaf] % 2:
		mmin = 3
		break
else:
	mmin = 1
print(mmin, mmax)