結果
| 問題 |
No.3113 The farthest point
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-13 02:01:30 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 592 bytes |
| コンパイル時間 | 388 ms |
| コンパイル使用メモリ | 12,160 KB |
| 実行使用メモリ | 136,960 KB |
| 最終ジャッジ日時 | 2025-04-13 02:01:45 |
| 合計ジャッジ時間 | 6,374 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 2 |
| other | AC * 2 TLE * 4 -- * 16 |
ソースコード
import sys
sys.setrecursionlimit(10**6)
n = int(input())
graph = [[] for _ in range(n)]
for i in range(n-1):
u, v, w = map(int, input().split())
graph[u-1].append((v-1, w))
graph[v-1].append((u-1, w))
ans = 0
def dfs(v, p):
global ans
dists = []
for u, w in graph[v]:
if u == p:
continue
dists.append(dfs(u, v) + w)
dists.sort(reverse=True)
if len(dists) >= 1:
ans = max(ans, dists[0])
if len(dists) >= 2:
ans = max(ans, dists[0] + dists[1])
return max(0, dists[0]) if dists else 0
dfs(0, -1)
print(ans)