結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 542 ms
104,168 KB
testcase_01 AC 37 ms
55,060 KB
testcase_02 AC 37 ms
53,252 KB
testcase_03 AC 38 ms
54,224 KB
testcase_04 AC 37 ms
53,504 KB
testcase_05 AC 38 ms
53,552 KB
testcase_06 AC 50 ms
64,224 KB
testcase_07 AC 36 ms
53,980 KB
testcase_08 AC 86 ms
76,732 KB
testcase_09 AC 114 ms
77,648 KB
testcase_10 AC 92 ms
76,628 KB
testcase_11 AC 246 ms
81,216 KB
testcase_12 AC 273 ms
82,688 KB
testcase_13 AC 280 ms
83,968 KB
testcase_14 AC 250 ms
80,120 KB
testcase_15 AC 269 ms
84,076 KB
testcase_16 AC 339 ms
90,060 KB
testcase_17 AC 280 ms
84,488 KB
testcase_18 AC 257 ms
81,872 KB
testcase_19 AC 249 ms
80,792 KB
testcase_20 AC 164 ms
78,564 KB
testcase_21 AC 296 ms
86,736 KB
testcase_22 AC 223 ms
87,528 KB
testcase_23 AC 213 ms
78,220 KB
testcase_24 AC 36 ms
53,440 KB
testcase_25 AC 431 ms
89,420 KB
testcase_26 AC 36 ms
53,792 KB
testcase_27 AC 35 ms
52,988 KB
testcase_28 AC 37 ms
54,564 KB
testcase_29 AC 36 ms
53,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