結果

問題 No.848 なかよし旅行
ユーザー O2MTO2MT
提出日時 2020-08-31 11:30:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 553 ms / 2,000 ms
コード長 1,016 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 82,548 KB
実行使用メモリ 104,164 KB
最終ジャッジ日時 2024-04-25 14:20:17
合計ジャッジ時間 6,999 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 553 ms
104,164 KB
testcase_01 AC 41 ms
54,352 KB
testcase_02 AC 36 ms
53,608 KB
testcase_03 AC 38 ms
53,544 KB
testcase_04 AC 36 ms
54,132 KB
testcase_05 AC 36 ms
54,464 KB
testcase_06 AC 52 ms
64,800 KB
testcase_07 AC 40 ms
53,536 KB
testcase_08 AC 89 ms
76,984 KB
testcase_09 AC 113 ms
77,776 KB
testcase_10 AC 91 ms
76,580 KB
testcase_11 AC 246 ms
80,912 KB
testcase_12 AC 268 ms
82,692 KB
testcase_13 AC 284 ms
84,220 KB
testcase_14 AC 251 ms
80,120 KB
testcase_15 AC 268 ms
84,076 KB
testcase_16 AC 333 ms
89,548 KB
testcase_17 AC 280 ms
84,236 KB
testcase_18 AC 262 ms
81,988 KB
testcase_19 AC 249 ms
80,508 KB
testcase_20 AC 164 ms
78,296 KB
testcase_21 AC 300 ms
87,064 KB
testcase_22 AC 231 ms
87,116 KB
testcase_23 AC 217 ms
78,068 KB
testcase_24 AC 37 ms
54,312 KB
testcase_25 AC 432 ms
89,416 KB
testcase_26 AC 37 ms
53,540 KB
testcase_27 AC 37 ms
54,000 KB
testcase_28 AC 37 ms
52,984 KB
testcase_29 AC 36 ms
53,876 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