結果

問題 No.848 なかよし旅行
ユーザー O2MTO2MT
提出日時 2020-08-31 11:29:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 581 ms / 2,000 ms
コード長 1,016 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 82,216 KB
実行使用メモリ 104,008 KB
最終ジャッジ日時 2024-04-25 14:19:55
合計ジャッジ時間 7,424 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 581 ms
104,008 KB
testcase_01 AC 41 ms
54,252 KB
testcase_02 AC 39 ms
52,744 KB
testcase_03 AC 40 ms
53,604 KB
testcase_04 AC 39 ms
53,952 KB
testcase_05 AC 39 ms
53,772 KB
testcase_06 AC 54 ms
64,124 KB
testcase_07 AC 41 ms
54,796 KB
testcase_08 AC 93 ms
76,728 KB
testcase_09 AC 116 ms
77,548 KB
testcase_10 AC 101 ms
76,912 KB
testcase_11 AC 272 ms
80,948 KB
testcase_12 AC 297 ms
82,680 KB
testcase_13 AC 305 ms
84,220 KB
testcase_14 AC 274 ms
80,252 KB
testcase_15 AC 294 ms
83,748 KB
testcase_16 AC 372 ms
89,288 KB
testcase_17 AC 305 ms
84,432 KB
testcase_18 AC 286 ms
81,740 KB
testcase_19 AC 268 ms
80,928 KB
testcase_20 AC 180 ms
78,688 KB
testcase_21 AC 328 ms
87,124 KB
testcase_22 AC 240 ms
87,436 KB
testcase_23 AC 225 ms
78,068 KB
testcase_24 AC 38 ms
53,744 KB
testcase_25 AC 459 ms
89,420 KB
testcase_26 AC 39 ms
53,152 KB
testcase_27 AC 39 ms
53,572 KB
testcase_28 AC 38 ms
54,420 KB
testcase_29 AC 40 ms
53,820 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