結果

問題 No.848 なかよし旅行
ユーザー chocoruskchocorusk
提出日時 2019-07-04 15:31:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 511 ms / 2,000 ms
コード長 822 bytes
コンパイル時間 342 ms
コンパイル使用メモリ 82,292 KB
実行使用メモリ 103,552 KB
最終ジャッジ日時 2024-04-25 13:47:47
合計ジャッジ時間 6,649 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 511 ms
103,552 KB
testcase_01 AC 38 ms
53,636 KB
testcase_02 AC 34 ms
53,260 KB
testcase_03 AC 35 ms
53,600 KB
testcase_04 AC 36 ms
53,824 KB
testcase_05 AC 36 ms
53,808 KB
testcase_06 AC 50 ms
64,920 KB
testcase_07 AC 37 ms
53,416 KB
testcase_08 AC 86 ms
76,896 KB
testcase_09 AC 106 ms
77,436 KB
testcase_10 AC 88 ms
76,792 KB
testcase_11 AC 233 ms
80,680 KB
testcase_12 AC 266 ms
82,004 KB
testcase_13 AC 259 ms
82,476 KB
testcase_14 AC 217 ms
79,380 KB
testcase_15 AC 265 ms
82,872 KB
testcase_16 AC 315 ms
87,740 KB
testcase_17 AC 255 ms
83,920 KB
testcase_18 AC 227 ms
80,208 KB
testcase_19 AC 222 ms
80,180 KB
testcase_20 AC 130 ms
77,976 KB
testcase_21 AC 272 ms
85,440 KB
testcase_22 AC 216 ms
87,100 KB
testcase_23 AC 176 ms
77,688 KB
testcase_24 AC 35 ms
53,660 KB
testcase_25 AC 332 ms
88,140 KB
testcase_26 AC 35 ms
54,188 KB
testcase_27 AC 36 ms
52,872 KB
testcase_28 AC 35 ms
52,956 KB
testcase_29 AC 36 ms
54,132 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