結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,204 KB
testcase_01 AC 78 ms
71,264 KB
testcase_02 AC 79 ms
71,268 KB
testcase_03 AC 82 ms
71,204 KB
testcase_04 AC 392 ms
144,164 KB
testcase_05 AC 405 ms
147,020 KB
testcase_06 AC 665 ms
147,164 KB
testcase_07 AC 828 ms
146,940 KB
testcase_08 AC 829 ms
147,120 KB
testcase_09 AC 568 ms
140,584 KB
testcase_10 AC 804 ms
169,624 KB
testcase_11 AC 592 ms
166,424 KB
testcase_12 AC 540 ms
164,780 KB
testcase_13 AC 815 ms
169,896 KB
testcase_14 AC 686 ms
144,760 KB
testcase_15 AC 595 ms
146,732 KB
testcase_16 AC 796 ms
148,720 KB
testcase_17 AC 968 ms
150,248 KB
testcase_18 AC 870 ms
142,088 KB
testcase_19 AC 698 ms
147,472 KB
testcase_20 AC 536 ms
126,492 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 77 ms
71,364 KB
testcase_24 AC 75 ms
71,368 KB
testcase_25 AC 75 ms
71,364 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