結果
問題 |
No.3113 The farthest point
|
ユーザー |
|
提出日時 | 2025-04-19 03:21:54 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 488 bytes |
コンパイル時間 | 447 ms |
コンパイル使用メモリ | 82,820 KB |
実行使用メモリ | 120,700 KB |
最終ジャッジ日時 | 2025-04-19 03:22:10 |
合計ジャッジ時間 | 14,562 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 WA * 17 |
ソースコード
N = int(input()) G = [[] for _ in range(N)] for i in range(N-1): u, v, w = map(int, input().split()) G[u-1].append((v-1, w)) G[v-1].append((u-1, w)) def dfs(v, p, dist): for u, w in G[v]: if u == p: continue dist[u] = dist[v] + w dfs(u, v, dist) dist = [0] * N dfs(0, -1, dist) leaf = [i for i in range(N) if len(G[i]) == 1] leaf.sort(key=lambda x: dist[x], reverse=True) v = leaf[0] dist = [0] * N dfs(v, -1, dist) print(max(dist))