import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import itertools N = int(readline()) graph = [[] for _ in range(N + 1)] for _ in range(N - 1): a, b = map(int, readline().split()) graph[a].append(b) graph[b].append(a) deg = [0] * (N + 1) for _ in range(N - 1): a, b = map(int, readline().split()) deg[a] += 1 deg[b] += 1 root = 1 parent = [0] * (N + 1) order = [] stack = [root] while stack: x = stack.pop() order.append(x) for y in graph[x]: if y == parent[x]: continue parent[y] = x stack.append(y) INF = 10 ** 9 dp = [[0, INF, INF, INF, INF, INF] for _ in range(N + 1)] for v in order[::-1]: a, b, c, d, e, f = dp[v] if deg[v] & 1: dp[v] = [ d, min(a, e), min(b, f), a + 1, min(b, d) + 1, min(c, e) + 1 ] else: dp[v] = [ a, min(b, d), min(c, e), d + 1, min(a, e) + 1, min(b, f) + 1 ] if v == root: break p = parent[v] A = [INF, INF, INF, INF, INF, INF] for a, b in itertools.product(range(6), repeat=2): i, k = divmod(a, 3) j, l = divmod(b, 3) i ^= j k += l if k > 2: continue c = 3 * i + k A[c] = min(A[c], dp[v][a] + dp[p][b]) dp[p] = A x = min(dp[root][:3]) print(N - 1 + x)