結果

問題 No.848 なかよし旅行
ユーザー ttrttr
提出日時 2020-02-17 22:00:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,024 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 388,784 KB
最終ジャッジ日時 2024-04-16 03:59:09
合計ジャッジ時間 16,438 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,356 ms
51,488 KB
testcase_01 AC 31 ms
10,880 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 30 ms
10,880 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 31 ms
10,880 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 788 ms
29,976 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 53 ms
11,904 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 30 ms
10,880 KB
testcase_25 TLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M,P,Q,T = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
    a,b,c = map(int, input().split())
    E[a-1].append((c, b-1))
    E[b-1].append((c, a-1))

import heapq
def dijkstra(s):
    inf = 10**18
    dist = [inf]*N
    dist[s] = 0
    h = []
    for e in E[s]:
        heapq.heappush(h, e)
    while h:
        temp = heapq.heappop(h)
        d = temp[0]
        v = temp[1]
        if dist[v] < d:
            continue
        dist[v] = d
        for e in E[v]:
            if dist[e[1]] < dist[v]+e[0]:
                continue
            heapq.heappush(h, (e[0]+d, e[1]))
    return dist

dist_0 = dijkstra(0)
dist_p = dijkstra(P-1)
dist_q = dijkstra(Q-1)
if dist_0[P-1]+dist_p[Q-1]+dist_q[0] <= T:
    ans = T
elif dist_0[P-1]*2 > T or dist_0[Q-1]*2 > T:
    ans = -1
else:
    ans = 0
    for i in range(N):
        if i == P-1 or i == Q-1:
            continue
        if (dist_0[i]+max(dist_p[i], dist_q[i]))*2 <= T:
            ans = max(ans, T-max(dist_p[i], dist_q[i])*2)

print(ans)
0