728x90
from collections import deque
import sys
input = sys.stdin.readline
N = int(input())
graph = [[] for _ in range (0,N+1)]
for i in range (0,N-1):
a,b = map(int,input().split())
graph[a].append(b)
graph[b].append(a)
ans = []
visited = [False for _ in range (0,N)]
for i in range (0,len(graph[1])):
deq = deque()
deq.appendleft(graph[1][i])
visited[0] = True
visited[graph[1][i]-1] = True
cnt = 1
while deq:
x = deq.popleft()
visited[x-1] = True
cnt += 1
for y in graph[x]:
if visited[y-1] == False:
deq.appendleft(y)
visited[y-1] = True
ans.append(cnt)
if len(graph[1]) == 1:
print(1)
else:
n = len(graph[1])-1
ans.sort()
answer = 0
for i in range (0,n):
answer += ans[i]
print(answer - n + 1)
'코딩' 카테고리의 다른 글
[BOJ] 1334 다음 팰린드롬 수 (0) | 2023.12.31 |
---|---|
[BOJ] 11055 가장 큰 증가하는 부분 수열 (1) | 2023.12.17 |
[Atcoder] ABC 329 D - Take Election Quick Report (1) | 2023.11.20 |
[Atcoder] ABC 327 D - Take ABC (1) | 2023.11.16 |
[Atcoder] ABC 327 C - Consecutive (0) | 2023.11.16 |