結果

問題 No.848 なかよし旅行
ユーザー brthyyjpbrthyyjp
提出日時 2020-08-11 05:42:17
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,439 bytes
コンパイル時間 135 ms
コンパイル使用メモリ 82,572 KB
実行使用メモリ 101,160 KB
最終ジャッジ日時 2024-04-17 17:01:18
合計ジャッジ時間 6,546 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 434 ms
101,060 KB
testcase_01 AC 40 ms
53,632 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 40 ms
52,992 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 40 ms
53,504 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 292 ms
89,728 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 96 ms
76,800 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 38 ms
52,944 KB
testcase_25 WA -
testcase_26 AC 40 ms
52,864 KB
testcase_27 AC 38 ms
52,480 KB
testcase_28 AC 38 ms
52,872 KB
testcase_29 AC 39 ms
52,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline

def main():
    n, m, p, q, t = map(int, input().split())
    p -= 1
    q -= 1
    edge = [[] for _ in range(n)]
    for i in range(m):
        a, b, c = map(int, input().split())
        a, b = a-1, b-1
        edge[a].append((c, b))
        edge[b].append((c, a))

    import heapq
    INF = 10**18
    def dijkstra_heap(s, edge, n):
        d = [INF] * n
        used = [True] * n #True: not used
        d[s] = 0
        used[s] = False
        edgelist = []
        for e in edge[s]:
            heapq.heappush(edgelist,e)
        while len(edgelist):
            minedge = heapq.heappop(edgelist)
            if not used[minedge[1]]:
                continue
            v = minedge[1]
            d[v] = minedge[0]
            used[v] = False
            for e in edge[v]:
                if used[e[1]]:
                    heapq.heappush(edgelist,(e[0]+d[v],e[1]))
        return d

    d1 = dijkstra_heap(0, edge, n)
    dp = dijkstra_heap(p, edge, n)
    dq = dijkstra_heap(q, edge, n)

    if d1[p]+dp[q]+d1[q] <= t:
        print(t)
        exit()

    if 2*d1[p]> t or 2*d1[q] > t:
        print(-1)
        exit()

    ans = -1
    for r in range(n):
        temp = d1[r]+max(dp[r], dq[r])
        temp *= 2
        #print(r, temp)
        if temp <= t:
            temp2 = 2*d1[r]+t-temp
            ans = max(temp2, ans)

    print(ans)

if __name__ == '__main__':
    main()
0