結果

問題 No.1833 Subway Planning
ユーザー ああいいああいい
提出日時 2022-02-05 12:09:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,314 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 86,780 KB
実行使用メモリ 399,340 KB
最終ジャッジ日時 2023-09-02 06:32:11
合計ジャッジ時間 20,258 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,492 KB
testcase_01 AC 74 ms
71,272 KB
testcase_02 AC 75 ms
71,304 KB
testcase_03 AC 78 ms
71,056 KB
testcase_04 AC 811 ms
399,340 KB
testcase_05 AC 700 ms
325,304 KB
testcase_06 AC 1,131 ms
323,576 KB
testcase_07 AC 1,328 ms
335,544 KB
testcase_08 AC 1,685 ms
397,608 KB
testcase_09 AC 977 ms
319,364 KB
testcase_10 AC 824 ms
150,744 KB
testcase_11 AC 617 ms
149,956 KB
testcase_12 AC 562 ms
147,156 KB
testcase_13 AC 829 ms
150,108 KB
testcase_14 AC 700 ms
146,424 KB
testcase_15 AC 626 ms
146,492 KB
testcase_16 AC 894 ms
151,572 KB
testcase_17 AC 1,057 ms
152,128 KB
testcase_18 AC 989 ms
145,712 KB
testcase_19 AC 738 ms
147,432 KB
testcase_20 AC 584 ms
129,940 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 77 ms
71,168 KB
testcase_24 AC 77 ms
71,204 KB
testcase_25 AC 78 ms
71,176 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)
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