結果

問題 No.848 なかよし旅行
ユーザー lllllll88938494lllllll88938494
提出日時 2023-05-10 19:21:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 732 ms / 2,000 ms
コード長 998 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 87,284 KB
実行使用メモリ 105,436 KB
最終ジャッジ日時 2023-08-17 22:56:09
合計ジャッジ時間 11,482 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 732 ms
105,436 KB
testcase_01 AC 91 ms
76,152 KB
testcase_02 AC 80 ms
71,476 KB
testcase_03 AC 81 ms
71,168 KB
testcase_04 AC 83 ms
71,420 KB
testcase_05 AC 83 ms
71,204 KB
testcase_06 AC 99 ms
76,224 KB
testcase_07 AC 90 ms
76,108 KB
testcase_08 AC 138 ms
78,352 KB
testcase_09 AC 162 ms
79,300 KB
testcase_10 AC 139 ms
78,596 KB
testcase_11 AC 356 ms
83,204 KB
testcase_12 AC 395 ms
84,732 KB
testcase_13 AC 423 ms
84,952 KB
testcase_14 AC 345 ms
82,700 KB
testcase_15 AC 410 ms
85,952 KB
testcase_16 AC 505 ms
90,136 KB
testcase_17 AC 398 ms
85,172 KB
testcase_18 AC 345 ms
83,124 KB
testcase_19 AC 353 ms
82,460 KB
testcase_20 AC 283 ms
79,864 KB
testcase_21 AC 430 ms
87,852 KB
testcase_22 AC 311 ms
89,464 KB
testcase_23 AC 267 ms
79,088 KB
testcase_24 AC 81 ms
71,504 KB
testcase_25 AC 498 ms
90,400 KB
testcase_26 AC 82 ms
71,292 KB
testcase_27 AC 83 ms
71,492 KB
testcase_28 AC 83 ms
71,204 KB
testcase_29 AC 83 ms
71,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify as hpi , heappop as hpop , heappush as hpush
n,m,p,q,t=map(int,input().split())
g = [[] for i in range(n+1)]
for _ in range(m):
    x,y,z = map(int,input().split())
    g[x].append((y,z))
    g[y].append((x,z))

def  daiku(i):
    inf=float('inf')
    d = [inf for i in range(n+1)]
    d[i] = 0
    done=[0 for i in range(n+1)]
    hp=[]
    hpush(hp,(d[i],i))
    
    while hp:
        _ ,now= hpop(hp)
        if done[now]:
            continue
        done[now] = 1
        for go,cost in g[now]:
            if d[go] > d[now] + cost:
                d[go] = d[now] + cost
                hpush(hp,(d[go],go))

    return d

one=daiku(1)
ps=daiku(p)
qs=daiku(q)

ans = -1
if one[p]+ps[q]+qs[1] <= t:
    ans = t
for i in range(1,n+1):
    for j in range(1,n+1):
        tt=one[i] + max(ps[i]+ ps[j],qs[j] + qs[i]) +one[j]
        sepa=max(ps[i] + ps[j] , qs[i] + qs[j])
        if tt > t:
            continue
        ans=max(t-sepa,ans)

print(ans)
        
        
0