結果

問題 No.1833 Subway Planning
ユーザー ああいいああいい
提出日時 2022-02-05 12:20:34
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,529 bytes
コンパイル時間 437 ms
コンパイル使用メモリ 87,180 KB
実行使用メモリ 169,864 KB
最終ジャッジ日時 2023-09-02 06:33:39
合計ジャッジ時間 16,339 ms
ジャッジサーバーID
(参考情報)
judge13 / judge16
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,528 KB
testcase_01 AC 71 ms
71,056 KB
testcase_02 AC 69 ms
71,496 KB
testcase_03 AC 69 ms
71,348 KB
testcase_04 AC 375 ms
144,316 KB
testcase_05 AC 378 ms
147,136 KB
testcase_06 AC 611 ms
147,240 KB
testcase_07 AC 752 ms
147,188 KB
testcase_08 AC 761 ms
147,412 KB
testcase_09 AC 528 ms
140,300 KB
testcase_10 AC 761 ms
169,768 KB
testcase_11 AC 592 ms
166,716 KB
testcase_12 AC 513 ms
165,136 KB
testcase_13 AC 759 ms
169,864 KB
testcase_14 AC 613 ms
144,712 KB
testcase_15 AC 571 ms
146,960 KB
testcase_16 AC 790 ms
148,972 KB
testcase_17 AC 944 ms
150,328 KB
testcase_18 AC 860 ms
142,308 KB
testcase_19 AC 698 ms
147,732 KB
testcase_20 AC 531 ms
126,676 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 71 ms
71,560 KB
testcase_24 AC 72 ms
71,216 KB
testcase_25 AC 72 ms
71,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

G = [[] for _ in range(N+1)]
edge = []
for _ in range(N-1):
    a,b,c = map(int,input().split())
    G[a].append((b,c))
    G[b].append((a,c))
    edge.append((c,a,b))
edge.sort(reverse = True,key = lambda x:x[0])
M,u,v = edge[0]
_min = edge[0][0]
import sys
sys.setrecursionlimit(10 ** 8)
parent = [0] * (N+1)
parent[u] = (u,M)
parent[v] = (v,M)
"""
def dfs(now,p):
    for v,c in G[now]:
        if v == p:continue
        parent[v] = (now,c)
        dfs(v,now)
"""
def dfs(now,p):
    stack = [(now,p)]
    while stack:
        now,p = stack.pop()
        for v,c in G[now]:
            if v == p:continue
            parent[v] = (now,c)
            stack.append((v,now))
dfs(u,v)
dfs(v,u)
memo = [0] * (N+1)
memo[u] = 1
memo[v] = 1
for i in range(1,N-1):
    c,a,b = edge[i]
    tmp = _min
    if parent[b][0] == a:
        a,b = b,a
    d = a
    while memo[a] == 0:
        memo[a] = 1
        if parent[a][1] < tmp:
            tmp = parent[a][1]
        a = parent[a][0]
    if a != u and a != v:
        break
    if M - tmp >= c:
        break
    if u == a:
        u = d
    else:
        v = d
    _min = tmp
while parent[v][0] != v:
    parent[v] = (parent[v][0],parent[v][1] - _min)
    v = parent[v][0]
while parent[u][0] != u:
    parent[u] = (parent[u][0],parent[u][1] - _min)
    u = parent[u][0]
parent[u] = (parent[u][0],parent[u][1] - _min)
parent[v] = (parent[v][0],parent[v][1] - _min)
ans = 0
for i in range(1,N+1):
    if parent[i][1] > ans:
        ans = parent[i][1]
print(ans)
    
0