結果

問題 No.848 なかよし旅行
ユーザー chocoruskchocorusk
提出日時 2019-07-04 15:31:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 597 ms / 2,000 ms
コード長 822 bytes
コンパイル時間 326 ms
コンパイル使用メモリ 87,100 KB
実行使用メモリ 105,208 KB
最終ジャッジ日時 2023-08-07 19:39:50
合計ジャッジ時間 8,314 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 597 ms
105,208 KB
testcase_01 AC 79 ms
71,136 KB
testcase_02 AC 75 ms
71,436 KB
testcase_03 AC 76 ms
71,624 KB
testcase_04 AC 76 ms
71,292 KB
testcase_05 AC 76 ms
71,292 KB
testcase_06 AC 89 ms
76,300 KB
testcase_07 AC 77 ms
71,384 KB
testcase_08 AC 125 ms
78,428 KB
testcase_09 AC 147 ms
79,316 KB
testcase_10 AC 129 ms
78,176 KB
testcase_11 AC 286 ms
82,748 KB
testcase_12 AC 312 ms
82,648 KB
testcase_13 AC 315 ms
84,528 KB
testcase_14 AC 259 ms
80,984 KB
testcase_15 AC 317 ms
84,284 KB
testcase_16 AC 374 ms
89,488 KB
testcase_17 AC 306 ms
86,076 KB
testcase_18 AC 276 ms
81,796 KB
testcase_19 AC 287 ms
82,036 KB
testcase_20 AC 176 ms
79,240 KB
testcase_21 AC 345 ms
87,244 KB
testcase_22 AC 280 ms
88,832 KB
testcase_23 AC 221 ms
78,748 KB
testcase_24 AC 76 ms
71,436 KB
testcase_25 AC 413 ms
90,036 KB
testcase_26 AC 76 ms
71,440 KB
testcase_27 AC 76 ms
71,524 KB
testcase_28 AC 75 ms
71,400 KB
testcase_29 AC 74 ms
71,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
import sys
n, m, p, q, t=map(int, input().split())
p-=1
q-=1
g=[[] for i in range(n)]
for i in range(m):
  a, b, c=map(int, input().split())
  a-=1
  b-=1
  g[a].append((c, b))
  g[b].append((c, a))
def dijkstra(s):
  d=[10**18]*n
  d[s]=0
  que=[]
  heapq.heappush(que, (0, s))
  while len(que)!=0:
    u=heapq.heappop(que)
    x=u[1]
    if d[x]<u[0]:
      continue
    for v in g[x]:
      y=v[1]
      if d[y]>d[x]+v[0]:
        d[y]=d[x]+v[0]
        heapq.heappush(que, (d[y], y))
  return d
d1=dijkstra(0)
dp=dijkstra(p)
dq=dijkstra(q)
if d1[p]+dp[q]+d1[q]<=t:
  print(t)
  sys.exit()
elif max(d1[p]*2, d1[q]*2)>t:
  print(-1)
  sys.exit()
ans=0
for i in range(n):
  for j in range(n):
    if d1[i]+max(dp[i]+dp[j], dq[i]+dq[j])+d1[j]<=t:
      ans=max(ans, t-max(dp[i]+dp[j], dq[i]+dq[j]))
print(ans)
0