이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
graph = dict()
visited = list()
visited = [False for i in range(300001)]
######################
n = int(input())
######################
def canHandle(v, crs):
num_children = 0
need_crews = 0
visited[v] = True
for i in range(len(graph[v])):
if visited[graph[v][i]] == False:
num_children += 1
need_crews += canHandle(graph[v][i], crs)
return max(0, num_children + need_crews - crs)
start = 0
end = n
for i in range(0, n - 1):
x = input()
x = x.split()
a = int(x[0])
b = int(x[1])
for_a = list()
for_b = list()
if a in graph and b in graph:
graph[a].append(b)
graph[b].append(a)
elif a in graph:
graph[a].append(b)
for_b = list()
for_b.append(a)
graph[b] = for_b
elif b in graph:
graph[b].append(a)
for_a = list()
for_a.append(b)
graph[a] = for_a
else:
for_a = list()
for_b = list()
for_a.append(b)
for_b.append(a)
graph[a] = for_a
graph[b] = for_b
while start < end:
midpoint = int((start + end) / 2)
for i in range(n):
visited[i] = False
if canHandle(1, midpoint) == 0:
end = midpoint
else:
start = 1 + midpoint
print(start)
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |