restructure zeta/** to storage/zeta/**

This commit is contained in:
2025-05-10 21:54:24 +09:00
parent 2886820691
commit 2f2e0759fd
407 changed files with 7 additions and 1 deletions

View File

@@ -0,0 +1,40 @@
def solve(N, E):
D = []
D.append((0, 1, 0))
finals = []
while D:
before, header, distance = D.pop(0)
nexts = E[header]
cnt = 0
for s in nexts:
if s[0] != before:
D.append((header, s[0], distance + s[1]))
cnt += 1
if cnt == 0:
finals.append((header, distance))
D = []
s1 = max(finals, key=lambda x: x[1])
D.append((0, s1[0], 0))
finals = []
while D:
before, header, distance = D.pop(0)
nexts = E[header]
cnt = 0
for s in nexts:
if s[0] != before:
D.append((header, s[0], distance + s[1]))
cnt += 1
if cnt == 0:
finals.append((header, distance))
return max(finals, key=lambda x: x[1])[1]
if __name__ == '__main__':
N: int = int(input())
E = [[] for _ in range(N + 1)]
for a, b, v in [map(int, input().split()) for _ in range(N - 1)]:
E[a].append((b, v))
E[b].append((a, v))
print(solve(N, E))