結果

問題 No.848 なかよし旅行
ユーザー chocoruskchocorusk
提出日時 2019-07-04 15:31:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 822 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 50,232 KB
最終ジャッジ日時 2024-04-16 07:02:53
合計ジャッジ時間 12,187 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,428 ms
50,232 KB
testcase_01 AC 32 ms
10,880 KB
testcase_02 AC 32 ms
10,880 KB
testcase_03 AC 32 ms
10,880 KB
testcase_04 AC 32 ms
11,008 KB
testcase_05 AC 32 ms
10,880 KB
testcase_06 AC 35 ms
10,880 KB
testcase_07 AC 32 ms
10,880 KB
testcase_08 AC 87 ms
11,008 KB
testcase_09 AC 92 ms
11,136 KB
testcase_10 AC 89 ms
11,136 KB
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

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