from collections import deque 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) # Build parent and children structure parent = [0] * (n + 1) children = [[] for _ in range(n + 1)] visited = [False] * (n + 1) q = deque([1]) visited[1] = True parent[1] = 0 while q: u = q.popleft() for v in adj[u]: if not visited[v] and v != parent[u]: parent[v] = u children[u].append(v) visited[v] = True q.append(v) # Compute child count for each node child_count = [0] * (n + 1) for u in range(1, n + 1): child_count[u] = len(children[u]) # Compute up_sum using BFS starting from root up_sum = [0] * (n + 1) q = deque([1]) up_sum[1] = child_count[1] - 1 # root's up_sum is children count -1 # Process nodes in BFS order to ensure parents are processed before children while q: u = q.popleft() for v in children[u]: up_sum[v] = (child_count[v] - 1) + up_sum[u] q.append(v) # Calculate the maximum value max_val = 1 # root's value is 1 for u in range(2, n + 1): p = parent[u] current_val = 1 + 2 * up_sum[p] if current_val > max_val: max_val = current_val print(max_val)