이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
import sys
sys.setrecursionlimit(200000)
def depth_first(h, p, t, ls, memo):
sm = 0
for elem in ls[h]:
if elem == p:
continue
depth_first(elem, h, t, ls, memo)
sm += memo[elem]
memo[h] = max(sm - t + 1, 1)
def main():
n = int(input())
ls = [[]] * (n+1)
memo = [0] * (n+1)
for _ in range(n - 1):
f, s = map(int, input().split())
f -= 1
s -= 1
ls[f].append(s)
ls[s].append(f)
s = 0
e = n
while not s > e:
m = (s + e) >> 1
t = m
depth_first(0, -1, t, ls, memo)
if memo[0] > 1:
s = m + 1
else:
e = m-1
print(s)
if __name__ == "__main__":
main()
# | 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... |