結果

問題 No.848 なかよし旅行
ユーザー O2MTO2MT
提出日時 2020-08-31 11:23:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 609 ms / 2,000 ms
コード長 1,015 bytes
コンパイル時間 360 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 105,080 KB
最終ジャッジ日時 2023-08-07 20:04:47
合計ジャッジ時間 8,750 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 609 ms
105,080 KB
testcase_01 AC 77 ms
71,152 KB
testcase_02 AC 74 ms
71,416 KB
testcase_03 AC 75 ms
71,416 KB
testcase_04 AC 75 ms
71,524 KB
testcase_05 AC 74 ms
71,436 KB
testcase_06 AC 88 ms
76,188 KB
testcase_07 AC 76 ms
71,496 KB
testcase_08 AC 126 ms
78,484 KB
testcase_09 AC 152 ms
79,108 KB
testcase_10 AC 133 ms
78,616 KB
testcase_11 AC 300 ms
83,112 KB
testcase_12 AC 327 ms
84,192 KB
testcase_13 AC 340 ms
85,488 KB
testcase_14 AC 300 ms
81,808 KB
testcase_15 AC 331 ms
85,876 KB
testcase_16 AC 403 ms
90,904 KB
testcase_17 AC 339 ms
86,664 KB
testcase_18 AC 315 ms
82,616 KB
testcase_19 AC 303 ms
82,720 KB
testcase_20 AC 211 ms
80,088 KB
testcase_21 AC 355 ms
88,384 KB
testcase_22 AC 276 ms
89,224 KB
testcase_23 AC 255 ms
78,972 KB
testcase_24 AC 75 ms
71,212 KB
testcase_25 AC 480 ms
90,384 KB
testcase_26 AC 74 ms
71,500 KB
testcase_27 AC 74 ms
71,312 KB
testcase_28 AC 75 ms
71,416 KB
testcase_29 AC 76 ms
71,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq


def dijkstra(s, graph):
    n = len(graph)-1
    dist = [float("inf") for i in range(n+1)]
    dist[s] = 0
    pq = []
    heapq.heapify(pq)
    heapq.heappush(pq, (0, s))
    while pq:
        mini_dis, node = heapq.heappop(pq)
        if dist[node] < mini_dis:
            continue
        for w, point in graph[node]:
            if dist[point] < w:
                continue
            newlen = dist[node]+w
            if newlen < dist[point]:
                heapq.heappush(pq, (newlen, point))
                dist[point] = newlen
    return dist

N,M,P,Q,T = map(int,input().split())
l = [[] for _ in range(N+1)] 
for _ in range(M):
  a,b,c = map(int,input().split())
  l[a].append((c,b))
  l[b].append((c,a))
  
A = dijkstra(1,l)
B = dijkstra(P,l)
C = dijkstra(Q,l)
ans = -1
if (A[P]+A[Q]+C[P]) <= T:
  print(T)
  exit()
for i in range(1,N+1):
  for j in range(1,N+1):
    if A[i]+B[i]+A[j]+B[j] <= T and A[i]+C[i]+A[j]+C[j] <= T:
      ans = max(ans,T-max(B[i]+B[j],C[i]+C[j]))

print(ans)
0