This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
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... |