結果

問題 No.848 なかよし旅行
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-06-21 15:55:46
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 1,391 bytes
コンパイル時間 1,307 ms
コンパイル使用メモリ 86,436 KB
実行使用メモリ 140,644 KB
最終ジャッジ日時 2023-09-05 01:53:25
合計ジャッジ時間 13,639 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,311 ms
140,644 KB
testcase_01 AC 81 ms
71,128 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 79 ms
70,992 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 80 ms
70,960 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 399 ms
98,440 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 198 ms
80,208 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 77 ms
71,124 KB
testcase_25 WA -
testcase_26 AC 76 ms
71,284 KB
testcase_27 AC 78 ms
71,008 KB
testcase_28 AC 79 ms
71,212 KB
testcase_29 AC 80 ms
71,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m,p,q,t=map(int,input().split())
abc=[list(map(int,input().split())) for _ in range(m)]
p,q=p-1,q-1
g=[[] for _ in range(n)]
for a,b,c in abc:
  a,b=a-1,b-1
  g[a].append([b,c])
  g[b].append([a,c])
inf=float('inf')
from0=[inf]*n
fromp=[inf]*n
fromq=[inf]*n

from0[0]=0
todo=[[0,0]]
from heapq import heappop,heappush
while todo:
  d,v=heappop(todo)
  if from0[v]<d:continue
  for nv,nd in g[v]:
    if from0[nv]>d+nd:
      from0[nv]=d+nd
      heappush(todo,[d+nd,nv])
fromp[p]=0
todo=[[0,p]]
from heapq import heappop,heappush
while todo:
  d,v=heappop(todo)
  if fromp[v]<d:continue
  for nv,nd in g[v]:
    if fromp[nv]>d+nd:
      fromp[nv]=d+nd
      heappush(todo,[d+nd,nv])
fromq[q]=0
todo=[[0,q]]
from heapq import heappop,heappush
while todo:
  d,v=heappop(todo)
  if fromq[v]<d:continue
  for nv,nd in g[v]:
    if fromq[nv]>d+nd:
      fromq[nv]=d+nd
      heappush(todo,[d+nd,nv])
# 別行動しない0->p->q->0
# vで別行動をはじめる。
# 0->v->p->v->0
# 0->v->q->v->0
# vで別行動をはじめるとする。v->p,q最短距離で向かい、再びvで合流するのが最適か
# N<=2000sなのでO(N^2)?ひっかけ?
tmp=from0[p]+fromp[q]+fromq[0]
#print(from0)
#print(fromp)
#print(fromq)
if tmp<=t:
  print(t)
  exit()
ans=-1
for v in range(n):
  tmp=from0[v]*2+max(fromp[v],fromq[v])*2
  if tmp<=t:
    ans=max(ans,t-max(fromp[v],fromq[v])*2)
print(ans)
0