結果

問題 No.848 なかよし旅行
ユーザー O2MTO2MT
提出日時 2020-08-31 11:25:10
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,015 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 82,528 KB
実行使用メモリ 104,012 KB
最終ジャッジ日時 2024-04-27 15:29:11
合計ジャッジ時間 8,212 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 632 ms
104,012 KB
testcase_01 AC 45 ms
55,636 KB
testcase_02 AC 42 ms
53,548 KB
testcase_03 AC 44 ms
53,980 KB
testcase_04 AC 42 ms
53,668 KB
testcase_05 AC 46 ms
53,548 KB
testcase_06 AC 60 ms
65,344 KB
testcase_07 WA -
testcase_08 AC 100 ms
76,740 KB
testcase_09 AC 134 ms
77,796 KB
testcase_10 WA -
testcase_11 AC 273 ms
81,060 KB
testcase_12 AC 308 ms
83,068 KB
testcase_13 AC 333 ms
84,472 KB
testcase_14 AC 276 ms
80,364 KB
testcase_15 AC 307 ms
83,944 KB
testcase_16 AC 400 ms
89,292 KB
testcase_17 AC 316 ms
84,624 KB
testcase_18 AC 289 ms
82,000 KB
testcase_19 AC 278 ms
80,664 KB
testcase_20 AC 190 ms
78,808 KB
testcase_21 AC 340 ms
87,132 KB
testcase_22 AC 256 ms
87,556 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 472 ms
89,296 KB
testcase_26 AC 42 ms
53,920 KB
testcase_27 AC 44 ms
53,148 KB
testcase_28 AC 42 ms
53,428 KB
testcase_29 AC 42 ms
53,680 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[1]) <= 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