結果
問題 |
No.3113 The farthest point
|
ユーザー |
|
提出日時 | 2025-04-20 17:48:37 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 892 bytes |
コンパイル時間 | 261 ms |
コンパイル使用メモリ | 12,160 KB |
実行使用メモリ | 87,448 KB |
最終ジャッジ日時 | 2025-04-20 17:49:10 |
合計ジャッジ時間 | 32,994 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 TLE * 2 |
ソースコード
from collections import defaultdict n = int(input()) graph = defaultdict(list) for _ in range(n - 1): u, v, w = map(int, input().split()) graph[u].append((v, w)) graph[v].append((u, w)) parent = [0] * (n + 1) order = [] stack = [1] parent[1] = -1 while stack: u = stack.pop() order.append(u) for v, w in graph[u]: if parent[v] == 0: parent[v] = u stack.append(v) best_down = [0] * (n + 1) answer = 0 for u in reversed(order): first = 0 second = 0 for v, w in graph[u]: if v == parent[u]: continue c = best_down[v] + w if c > first: second = first first = c elif c > second: second = c if first < 0: first = 0 if second < 0: second = 0 answer = max(answer, first + second) best_down[u] = first print(answer)